guile-user
[Top][All Lists]
Advanced

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

Re: strange behaviour of (floor .)


From: Paul Emsley
Subject: Re: strange behaviour of (floor .)
Date: Mon, 28 Dec 2009 19:42:35 +0000
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

address@hidden wrote:
Hej all :)

I'm a little confused by the results of (floor .) in a simple
computation to get the fractional part of a monetary value. Maybe
someone can comment on this, as especially in the last test case below
the results seem very strange to me...
The starting point is:
guile> (rationalize (floor (* (- 12.34 (floor 12.34)) 100)) .0)
33

The actual result shoud be 34.


That's one of the answers you will get if you use a computer to calculate the results.
33 is the other.

floor is working fine.

Consider the following:

(floor (* (- 12.34000000000001 (floor 12.34)) 100))
(floor (* (- 12.33999999999999 (floor 12.34)) 100))


Given that floating point number storage is not precise, different values is entirely reasonable. You have to be a bit more sophisticated in your floor usage.


Paul.





reply via email to

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