up
previous
next
FloatStr, MantissaAndExponent
Syntax
FloatStr(X:RAT):STRING
FloatStr(X:RAT, Prec:INT):STRING
MantissaAndExponent(X:RAT, Prec:INT):RECORD
Summary
convert rational number to a float string
Description
The first two functions convert a rational number X into a (decimal)
floating point string. The optional second argument Prec says how many
decimal digits to include in the mantissa; the default value is 10.
Note that an exponent is always included; the only exception being the
number zero which is converted to the string
0
.
The third 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.
example
FloatStr(2/3); -- last printed digit is rounded
6.666666667*10^(-1)
-------------------------------
FloatStr(7^510); -- no arbitrary limit on exponent range
1.000000938*10^431
-------------------------------
FloatStr(1/81, 50); -- precision of mantissa specified by user
1.2345679012345679012345679012345679012345679012346*10^(-2)
-------------------------------
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]
-------------------------------
See Also