Rick Taube <[EMAIL PROTECTED]> writes:

> this behavior of inexact->exact in guile 1.7.1 causes my program to
> become confused:
>
> guile> (inexact->exact 48.0)
> 48
> guile> (inexact->exact (* .1 480.0))
> 48
> guile> (inexact->exact (* (- 1.1 1) 480.0))
> 3377699720527875/70368744177664

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


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

Reply via email to