exact rationalization of big floats



Here's one.   Use it only on bigfloats, though.

(defun $myrat(x)(* (cadr x)(expt 2 (- (caddr x) (third (car x))))))

oh,  but this won't really work in maxima since it produces
a common lisp rational, not a maxima rational.

So wrap around the answer..

(defun makemaximaratfromCLrat(x)(if (integerp x) x (list '(rat simp)(numerator x)(denominator x))))

You could put some error checks around if you want.

C6) bfloat(1.0e-1);
Warning:  Float to bigfloat conversion of 0.10000000000000001
(D6) 				    1.0B-1
(C7) myrat(%);
(D7)   4056481920730334084789450257203/40564819207303340847894502572032

RJF



Barton Willis wrote:

> 
> Is there a function that does exact big float to rational
> conversions?  It would work like the Common Lisp function
> 'rationalize' for big floats:
> 
>     (rationalize 0.1)
>     3602879701896397/36028797018963968
> 
> The Maxima function 'rat' doesn't do exact conversion:
> 
> (%i1) rat(0.1);
> RAT replaced 0.1 by 1//10 = 0.1
> (%o1) 1/10
> (%i2) rat(0.1), ratepsilon : 1.0e-50;
> RAT replaced 0.1 by 1//10 = 0.1
> (%o2) 1/10
> 
> 
> Barton
> 
> _______________________________________________
> Maxima mailing list
> Maxima@math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima