guile-user
[Top][All Lists]
Advanced

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

Re: inexact->exact in 1.7.1


From: Rick Taube
Subject: Re: inexact->exact in 1.7.1
Date: Fri, 15 Apr 2005 12:46:23 -0500

Thank you, i was porting my code from 1.6.7 to the new version where it broke and I forgot about this. time for a m-x tags-search!
--rick


This happens because Guile now has exact rationals.  This NEWS entry
explains the behavior:

    ** inexact->exact no longer returns only integers.

    Without exact rationals, the closest exact number was always an
integer, but now inexact->exact returns the fraction that is exactly
    equal to a floating point number.  For example:

        (inexact->exact 1.234)
        => 694680242521899/562949953421312

    When you want the old behavior, use 'round' explicitely:

        (inexact->exact (round 1.234))
        => 1


In your case, "1.1" is not exactly 11/10 since IEEE double can not
represent that number exactly.  You can write "#e1.1" instead, if you
want an exact 11/10:

    guile> #e1.1
    11/10
    guile> (inexact->exact (* (- #e1.1 1) #e480.0))
    48

A IEEE double can not represent 0.1 exactly either, and you just got
lucky that (* 0.1 480.0) is exactly 48:

guile> (- (* 0.1 480.0)
          (* (- 1.1 1) 480.0))
-4.2632564145606e-14





reply via email to

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