From: Roger Pack Date: 2009-03-01T01:22:29+09:00 Subject: [ruby-core:22595] Re: suggestions for float On Sat, Feb 21, 2009 at 11:59 PM, Roger Pack wrote: > 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? I guess there's not too much feedback on this one :) I for one find floating point rounding errors always surprising, so defaulting to BigDecimal would at least help this ruby user. Thanks! -=r