On Sat, Feb 21, 2009 at 11:59 PM, Roger Pack <rogerdpack / gmail.com> 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=3D989431
> 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:
>
> =A0some_float =3D=3D 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. =A0I realize it would cause
> some problems but in the long run would help
>
> ex:
>
> require 'bigdecimal'
> a =3D (BigDecimal.new( "10.11") * 100).to_i
> b =3D (BigDecimal.new( "10.12") * 100).to_i
> puts a =3D=3D b # false
> a =3D (10.11 * 100).to_i
> b =3D (10.12 * 100).to_i
> puts a =3D=3D 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!
-=3Dr