Created
March 8, 2010 05:39
-
-
Save Neurogami/324902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A ruby WTF ... | |
***************************************************************** | |
UPDATE: See http://redmine.ruby-lang.org/issues/show/1735#note-2 | |
A bug in an optimization setting does this. | |
***************************************************************** | |
irb(main):003:0* x = 0.05 | |
=> 5.0 | |
or this: | |
irb(main):001:0> x = 0.56 + 0.006 | |
=> 62.0 | |
Floats are treated as ints. | |
I'm thinking it's some locale setting, but I have no idea where that would come from. | |
And I can do this madness: | |
irb(main):005:0> x = 1.0/8.0 | |
=> 0.125 | |
irb(main):006:0> x.to_s | |
=> "0.125" | |
irb(main):007:0> y = eval(x.to_s) | |
=> 125.0 | |
irb(main):008:0> | |
More observations: | |
irb(main):001:0> x = 0.5 | |
=> 5.0 | |
irb(main):002:0> x.type | |
(irb):2: warning: Object#type is deprecated; use Object#class | |
=> Float | |
irb(main):003:0> y = 1.0/5.0 | |
=> 0.2 | |
irb(main):004:0> y.type | |
(irb):4: warning: Object#type is deprecated; use Object#class | |
=> Float | |
irb(main):005:0> z = y | |
=> 0.2 | |
irb(main):006:0> z | |
=> 0.2 | |
irb(main):007:0> | |
ruby 1.8.6 (2009-08-04 patchlevel 383) [i686-linux] | |
Installed from source on Ubuntu 9.10 | |
Linux ubu910-hubris 2.6.31-19-generic #56-Ubuntu SMP Thu Jan 28 01:26:53 UTC 2010 i686 GNU/Linux | |
Have no idea what a float gets interpreted as an Integer. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment