[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: real to rational



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.