* inexact->exact in 1.7.1
@ 2005-04-15 17:13 Rick Taube
2005-04-15 17:24 ` Per Bothner
2005-04-15 17:36 ` Marius Vollmer
0 siblings, 2 replies; 4+ messages in thread
From: Rick Taube @ 2005-04-15 17:13 UTC (permalink / raw)
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
guile>(quit)
$ uname -a
Darwin pinhead.music.uiuc.edu 7.8.0 Darwin Kernel Version 7.8.0: Wed
Dec 22 14:26:17 PST 2004; root:xnu/xnu-517.11.1.obj~1/RELEASE_PPC
Power Macintosh powerpc
-rick
i attempted to see if guile 1.7.2 fixes this but it doesnt build on
darwin. perhaps someone could tell me
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: inexact->exact in 1.7.1
2005-04-15 17:13 inexact->exact in 1.7.1 Rick Taube
@ 2005-04-15 17:24 ` Per Bothner
2005-04-15 17:36 ` Marius Vollmer
1 sibling, 0 replies; 4+ messages in thread
From: Per Bothner @ 2005-04-15 17:24 UTC (permalink / raw)
Cc: guile-user
Rick Taube wrote:
> this behavior of inexact->exact in guile 1.7.1 causes my program to
> become confused:
I suspect you're the one who is confused.
You need to learn about floating-point arithmetic.
(- 1.1 1) does not necessarily give the same result as 0.1.
> i attempted to see if guile 1.7.2 fixes this
Why do you think there is a bug?
--
--Per Bothner
per@bothner.com http://per.bothner.com/
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: inexact->exact in 1.7.1
2005-04-15 17:13 inexact->exact in 1.7.1 Rick Taube
2005-04-15 17:24 ` Per Bothner
@ 2005-04-15 17:36 ` Marius Vollmer
2005-04-15 17:46 ` Rick Taube
1 sibling, 1 reply; 4+ messages in thread
From: Marius Vollmer @ 2005-04-15 17:36 UTC (permalink / raw)
Cc: guile-user
Rick Taube <taube@uiuc.edu> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: inexact->exact in 1.7.1
2005-04-15 17:36 ` Marius Vollmer
@ 2005-04-15 17:46 ` Rick Taube
0 siblings, 0 replies; 4+ messages in thread
From: Rick Taube @ 2005-04-15 17:46 UTC (permalink / raw)
Cc: guile-user
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
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-04-15 17:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-15 17:13 inexact->exact in 1.7.1 Rick Taube
2005-04-15 17:24 ` Per Bothner
2005-04-15 17:36 ` Marius Vollmer
2005-04-15 17:46 ` Rick Taube
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).