decimal

© 2011 John Abbott
GNU Free Documentation License, Version 1.2



CoCoALib Documentation Index

User documentation for file decimal.H

These functions are to help visualize numbers in a more comprehensible format.

See also the functions ILogBase (in the doc for ZZ and QQ).

Maintainer documentation

The functions MantissaAndExponent do the real work. The only tricky parts were deciding how to round in the case of a tie, and correct behaviour when the mantissa "overflows". I finally decided to round away from zero: it is easy to implement, and I wanted a solution which was symmetric about zero, so that MantissaAndExponent applied to N and to -N would always give the same result except for sign.

Mantissa overflow occurs only when the last digit rounds away from zero, and all the digits were 9 before rounding. This case would never occur if I'd chosen simply to truncate when forming the mantissa.

Printing of a MantExp structure is simple rather than elegant.

Bugs, shortcomings and other ideas

The conversion in MantissaAndExponent is rather slow when the input number is large.

In principle the call to ILogBase could fail because of overflow; but in that case ILogBase itself should report the problem.

In principle a mantissa overflow could trigger an exponent overflow (i.e. if the exponent was already the largest possible long).

Main changes

2011