Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Created July 15, 2011 17:55
Show Gist options
  • Save donpdonp/1085169 to your computer and use it in GitHub Desktop.
Save donpdonp/1085169 to your computer and use it in GitHub Desktop.
floating point crazyness
$ irb
irb(main):001:0> RUBY_VERSION
=> "1.9.2"
irb(main):002:0> 1.8 + 0.1
=> 1.9000000000000001
irb(main):003:0> 1.8 + 0.1 == 1.9
=> false
irb(main):004:0>
## Ruby 1.8 wont even let you know whats going on!
ree-1.8.7-2011.03 :008 > RUBY_VERSION
=> "1.8.7"
ree-1.8.7-2011.03 :009 > 1.8 + 0.1
=> 1.9
ree-1.8.7-2011.03 :010 > 1.8 + 0.1 == 1.9
=> false
ree-1.8.7-2011.03 :011 >
@LeifW
Copy link

LeifW commented Jul 15, 2011

It'd be nice if it could keep track of significant figures or something and round off the noise at the end. Maybe that's what that MPFR library is for. I just wish things like Decimal and Rational were as small and quick as Float.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment