up previous next
convert rational number to a float
MantissaAndExponent(X:RAT, Prec:INT):RECORD
|
This function converts a rational number into a Record with
components named Mantissa and Exponent. The value of the Exponent
field is the unique integer E such that
1 <= X*10^E <= 10, and the
value of Mantissa is the nearest integer to
(X*10^E)*10^(Prec-1).
As an exception the case of X=0 always produces zero values for
both components of the record.
FloatStr(1/2); -- trailing zeroes are not suppressed
5.000000000*10^(-1)
-------------------------------
MantissaAndExponent(1/2,3); -- 1/2 = 5.00*10^(-1)
Record[Exponent = -1, Mantissa = 500]
-------------------------------
MantissaAndExponent(0.9999, 3); -- 0.9999 rounds up to give 1.00
Record[Exponent = 0, Mantissa = 100]
-------------------------------
|