Home

Arithmetic: The Logarithm of a Number

 

LnXP1

The LnXP1() function is used to calculate the natural logarithm of a number that is being incremented to 1. The syntax of this function is

Extended __fastcall LnXP1(Extended X);

When executing, this function takes one argument, X, adds 1 to X, and then calculates the natural logarithm, also called the Napierian logarithm, of the new number. The formula used is

Result = ln(X+1)

Here is an example:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Extended X, Result;

	X = StrToFloat(Edit1->Text);
	Result = LnXP1(X);
	Edit2->Text = FloatToStr(Result);
}
//---------------------------------------------------------------------------

Log10

The Log10() function calculates the base 10 logarithm of a number. The syntax of this function is:

Extended __fastcall Log10(Extended X);

The number to be evaluated is passed as the argument X. The function returns the logarithm on base 10 using the formula:

y = log10x

which is equivalent to

x = 10y

Here is an example:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Extended X, Result;

	X = StrToFloat(Edit1->Text);
	Result = Log10(X);
	Edit2->Text = FloatToStr(Result);
}
//---------------------------------------------------------------------------

Log2

The Log2() function is used to calculate the logarithm of a number on base 2. The syntax of the function is:

Extended __fastcall Log2(Extended X);

The variable whose logarithmic value will be calculated is passed as argument X to the function. The function uses the formula:

Y = log2x

This is the same as

x = 2y

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Extended X, Result;

	X = StrToFloat(Edit1->Text);
	Result = Log2(X);
	Edit2->Text = FloatToStr(Result);
}
//---------------------------------------------------------------------------

 

LogN

The LogN() function is used to calculate the logarithmic value of a number to the desired base. Its syntax is:

Extended __fastcall LogN(Extended Base, Extended Number);

This function takes two arguments. The second, Number, is the variable whose value will be evaluated. The first argument, Base, is used as the base of the logarithm. The formula used by this function is:

y = logbx

which is the same as

x = by
For the LogN() function, this formula would be:

LogN(Base, Number) = NumberBase;

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Extended Base, Number, Result;

	Base = StrToFloat(Edit1->Text);
	Number = StrToFloat(Edit2->Text);
	Result = LogN(Base, Number);

	Edit3->Text = FloatToStr(Result);
}
//---------------------------------------------------------------------------
 
Home Copyright © 2004-2016, FunctionX, Inc.