numlib::decimal -- infinite
representation of rational numbers
Introductionnumlib::decimal(q) computes the decimal
expansion of a rational number q.
Call(s)numlib::decimal(q)
Parametersq |
- | nonnegative rational number |
Returnsnumlib::decimal(q) returns an expression
sequence consisting of nonnegative integers or an expression sequence
consisting of nonnegative integers and terminated by a list of
nonnegative integers.
Detailsq is a nonnegative rational number whose decimal
expansion is finite, then numlib::decimal(q)
returns the expression sequence starting with the integral part of
q and followed by the digits after the decimal point.q is a nonnegative rational number whose decimal
expansion is infinite, then
numlib::decimal(q) returns the expression
sequence starting with the integral part of q, followed by
the digits of the pre-period and terminated with a list, containing the
digits of a minimal period.numlib::decimal returns an error if the argument is a
number but not a rational number .
Example
1Computing the decimal expansion of :
>> numlib::decimal(1999)
1999
Example
2Computing the (finite) decimal expansion of :
>> numlib::decimal(52187/78125)
0, 6, 6, 7, 9, 9, 3, 6
Example
3Computing the (infinite) decimal expansion of :
>> numlib::decimal(111/7)
15, [8, 5, 7, 1, 4, 2]
Example
4Computing the (infinite) decimal expansion of :
>> numlib::decimal(37/28)
1, 3, 2, [1, 4, 2, 8, 5, 7]