[Top][All Lists]

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

[Gcl-devel] Re: [Maxima] float to bfloat

From: Raymond Toy
Subject: [Gcl-devel] Re: [Maxima] float to bfloat
Date: Fri, 23 Jan 2004 10:20:33 -0500
User-agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.5 (celeriac, usg-unix-v)

>>>>> "Camm" == Camm Maguire <address@hidden> writes:

    Camm> (defun test-f (x i) (multiple-value-bind (q r s) (integer-decode-float
    Camm> x) (format t "~S~%" x) (and (eql x (float (* q (expt 2 r)))) (eql
    Camm> (float (float-rationalize x)) x )(if (> i 0) (test-f (float (* (+ q 1)
    Camm> (expt 2 r))) (- i 1)) t))))

    Camm> (test-f 1.0 10)
    Camm> 1.0
    Camm> 1.0000000000000002
    Camm> NIL

    Camm> (float (float-rationalize 1.0000000000000002))

    Camm> 1.0000000000000004

Could be a problem with GCL's float reader/writer.  Perhaps it's not
reading/writing 1.000...2 correctly.

An alternative is to use CMUCL's rationalize function.  This was
stolen from Clisp (with permission) and converted to Lisp.  Bruno
Haible tends to implement very good numerical stuff.  I haven't tested
whether it works in for possible numbers.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]