Home

Math Functions: The Mantissa and the Exponent

     

The ldexp() Function

 

The C/C++ ldexp() function takes the mantissa and the exponent numbers and returns a floating number:

double ldexp(double x, int y);
long double ldexpl(long double x, int y);
   

The function uses the formula:

Result = x * 2y

Here is an example:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	double x, Result;
	int y;

	x = StrToFloat(Edit1->Text);
	y = StrToInt(Edit2->Text);
	Result = ldexp(x, y);

	Edit3->Text = FloatToStr(Result);
}
//---------------------------------------------------------------------------

The ldexp() function works on double-precision numbers while the ldexpl() uses long doubles.

The Ldexp() Function

The VCL’s Ldexp() function is used to calculate a number that is derived from a known mantissa and an exponent numbers:

Extended __fastcall Ldexp(Extended X, int P);

To perform this calculation, the function uses the formula:

Result = X * 2P
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	float Source = 450.04;
	float Exp = 10.25;
	
	double Result = Ldexp(Source, Exp);
	Edit1->Text = Result;
}
//---------------------------------------------------------------------------
 
 
     
 

Home Copyright © 2010-2016, FunctionX