Skip to content

Instantly share code, notes, and snippets.

@Neurogami
Created March 8, 2010 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Neurogami/324902 to your computer and use it in GitHub Desktop.
Save Neurogami/324902 to your computer and use it in GitHub Desktop.
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