![]() |
Arithmetic: The Mantissa and Exponent |
double ldexp(double x, int y); long double ldexpl(long double x, int y); The C/C++ ldexp() function takes the mantissa and the exponent numbers and returns a floating number. 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.
Extended __fastcall Ldexp(Extended X, int P); The VCL's Ldexp() function is used to calculate a number that is derived from a known mantissa and an exponent numbers. 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 © 2004-2010 FunctionX, Inc. | |