CoCoA:MantissaAndExponent
From ApCoCoAWiki
MantissaAndExponent
convert rational number to a float
Description
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 <formula>1 <less_eq/> X*10^E <less_eq/> 10</formula>, and the value of Mantissa is the nearest integer to <formula>(X*10^E)*10^(Prec-1)</formula>. As an exception the case of X=0 always produces zero values for both components of the record.
Example
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] -------------------------------
Syntax
MantissaAndExponent(X:RAT, Prec:INT):RECORD
<type>rat</type> <type>string</type>