From: Robert Klemme Date: 2009-06-06T20:25:11+09:00 Subject: Re: rounding errors? On 06.06.2009 05:46, s.ross wrote: > 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. Agreed. And, btw, with BigDecimal even Ruby comes up with more "natural" results: require 'bigdecimal' x = BigDecimal.new "0.29" x *= 100 puts x printf "%f %10.8f\n", x, x -> 0.29E2 29.000000 29.00000000 > However, the correct answer is: The > result of evaluating this expression is implementation-specific. Actually, this is only half true: if the implementation is IEEE-754 standards conform then it must yield certain results - regardless of implementation. I believe nowadays most if not all math libraries conform to the standard so you should expect to see the same results from all implementations. I would assume that differences are mostly due to numeric data type (see your C example) and conversion for printing (e.g. how many places are output by default). http://en.wikipedia.org/wiki/IEEE_754 http://grouper.ieee.org/groups/754/ > The moral of the story is not "use Lisp". The moral is use floating > point numbers with great care. Exactly. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/