From: pjb@... (Pascal J. Bourguignon) Date: 2009-06-06T17:00:14+09:00 Subject: Re: rounding errors? "s.ross" writes: > On Jun 5, 2009, at 7:15 PM, Pascal J. Bourguignon wrote: > >> Pete Hodgson writes: >> >>> :~$ ruby -e "p ((0.29)*100).to_i" >>> 28 >>> >>> Really?! I know that digital storage of floating point numbers can >>> lead >>> to things like this, but this one seems a little extreme to me. >> >> You may try a true Lisp instead of a Matzacred Lisp: >> >> $ clisp -q -norc -x '(values (truncate (* 0.29 100)))' >> 29 >> >> -- >> __Pascal Bourguignon__ > > The result of the calculation is undefined in pretty much any > language. The loose definition of the expression is "return a value > 100 times a value approximating 29 and truncated to an integer using > the algorithm of your choice." So, you claim the *only* right answer > must be the one yielded by Lisp. However, the correct answer is: The > result of evaluating this expression is implementation-specific. My point being that there are some implementations that are more useful and helpful than others. > The moral of the story is not "use Lisp". The moral is use floating > point numbers with great care. Oh, geez, I totally forgot, this is a > Ruby list, not a C list. -- __Pascal Bourguignon__