T
Tim Pease
I ran across some peculiar behavior yesterday when working with large
floating point values. Here is a small script that demonstrates the
behavior. My question is, is this the expected behavior or is this a
bug in Float?
"(#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) " +
"[#{RUBY_PLATFORM}]"
puts "Float::MAX = #{Float::MAX}"
puts "1.0e+300 = #{1.0e+300}"
puts "1.0e+301 = #{1.0e+301}"
puts "1.0e+308 = #{1.0e+308}"
puts "1.0e+700 = #{1.0e+700}"
# EOF
When I run this script on my Windows machine, it produces the output I
would expect -- i.e. numbers above Float::MAX are "Infinity" and
numbers below Float::MAX are valid floating point numbers.
Float::MAX = 1.79769313486232e+308
1.0e+300 = 1.0e+300
1.0e+301 = 1.0e+301
1.0e+308 = 1.0e+308
1.0e+700 = Infinity
Now, when I run the exact same script on a Solaris machine, some odd
things start to happen
Float::MAX = 1.79769313486232e+308
1.0e+300 = 1.0e+300
1.0e+301 = NaN
1.0e+308 = NaN
1.0e+700 = 8.55180271847103e+116
Whey are valid floats being treated as NaN? Better yet, why does
1.0e+700 get evaluated to 8.5518027e+116?
Once more on the Windows 1-click installed version of Ruby.
Float::MAX = 1.79769313486232e+308
1.0e+300 = 1.0e+300
1.0e+301 = NaN
1.0e+308 = NaN
1.0e+700 = 1.0e+189
Any thoughts on this one? I encourage you to copy the float_bug.rb
script and try it out for yourself.
Blessings,
TwP
floating point values. Here is a small script that demonstrates the
behavior. My question is, is this the expected behavior or is this a
bug in Float?
puts "ruby #{RUBY_VERSION} " +cat float_bug.rb
"(#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) " +
"[#{RUBY_PLATFORM}]"
puts "Float::MAX = #{Float::MAX}"
puts "1.0e+300 = #{1.0e+300}"
puts "1.0e+301 = #{1.0e+301}"
puts "1.0e+308 = #{1.0e+308}"
puts "1.0e+700 = #{1.0e+700}"
# EOF
When I run this script on my Windows machine, it produces the output I
would expect -- i.e. numbers above Float::MAX are "Infinity" and
numbers below Float::MAX are valid floating point numbers.
ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-cygwin]ruby -w float_bug.rb
Float::MAX = 1.79769313486232e+308
1.0e+300 = 1.0e+300
1.0e+301 = 1.0e+301
1.0e+308 = 1.0e+308
1.0e+700 = Infinity
Now, when I run the exact same script on a Solaris machine, some odd
things start to happen
ruby 1.8.5 (2006-12-25 patchlevel 12) [sparc-solaris2.8]ruby -w float_bug.rb
Float::MAX = 1.79769313486232e+308
1.0e+300 = 1.0e+300
1.0e+301 = NaN
1.0e+308 = NaN
1.0e+700 = 8.55180271847103e+116
Whey are valid floats being treated as NaN? Better yet, why does
1.0e+700 get evaluated to 8.5518027e+116?
Once more on the Windows 1-click installed version of Ruby.
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]ruby -w float_bug.rb
Float::MAX = 1.79769313486232e+308
1.0e+300 = 1.0e+300
1.0e+301 = NaN
1.0e+308 = NaN
1.0e+700 = 1.0e+189
Any thoughts on this one? I encourage you to copy the float_bug.rb
script and try it out for yourself.
Blessings,
TwP