gu...@mails.selgrad.org 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