[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: real to rational
- To: bright@ENH.NIST.GOV, info-mcl@cambridge.apple.com
- Subject: Re: real to rational
- From: Ranson <ranson@LANNION.cnet.fr>
- Date: 07 Jan 93 15:46:00 GMT
- X400-received: by /PRMD=inria/ADMD=atlas/C=FR/; Relayed; 07 Jan 93 15:46:11+0100
- X400-received: by /PRMD=CNET/ADMD=ATLAS/C=FR/; Relayed; 07 Jan 93 15:46:00 GMT
Common Lisp already does that for you! There are two functions RATIONAL and
RATIONALIZE that take one non-complex number argument and return a rational.
RATIONAL assumes floats are exact and returns the rational that has exactly
the same value. RATIONALIZE knows about the limited precision of floats, and
tries to find a rational with small numerator and denominator that is equal
to the argument +/- the precision of the floating-point format.
RATIONAL is faster, but RATIONALIZE gives more pleasant results.
Daniel.