Floating point rounding errors are common and "annoying"
A few thoughts on this, for fun.
Kurt Stephens suggested awhile back
"
Perhaps Ruby should do what Common Lisp implementations have been doing:
http://portal.acm.org/citation.cfm?id=989431
http://kurtstephens.com/files/p372-steele.pdf
ftp://netlib.bell-labs.com/netlib/fp/gdtoa.tgz
Perhaps the default Float#to_s formatting should not throw away
necessary precision, so that:
some_float == eval("#{some_float}")
is always true.
"
that would be nice.
Another more radical approach would be to default decimal style
numbers to BigDecimal, instead of Float. I realize it would cause
some problems but in the long run would help
ex:
require 'bigdecimal'
a = (BigDecimal.new( "10.11") * 100).to_i
b = (BigDecimal.new( "10.12") * 100).to_i
puts a == b # false
a = (10.11 * 100).to_i
b = (10.12 * 100).to_i
puts a == b # true
Just throwing it out there.
Thoughts?
-=r