Bug #922
closed
Float == is false when should be true
Added by amandanicholas (Amanda Nicholas) almost 16 years ago.
Updated over 13 years ago.
Description
=begin
In irb on Ruby 1.8.6 (ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]) and 1.8.7 (ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux])
896.5 * 0.83
=> 744.095
896.5 * 0.83 == 744.095
=> false
=end
=begin
On Dec 22, 2008, at 19:55 PM, Amanda Nicholas wrote:
Bug #922: Float == is false when should be true
http://redmine.ruby-lang.org/issues/show/922
Author: Amanda Nicholas
Status: Open, Priority: Normal
Target version: Ruby 1.8.7
In irb on Ruby 1.8.6 (ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-
linux]) and 1.8.7 (ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux])
896.5 * 0.83
=> 744.095
896.5 * 0.83 == 744.095
=> false
They're not the same, Ruby truncates the true value for display
purposes:
irb(main):001:0> a = 896.5* 0.83
=> 744.095
irb(main):002:0> b = 744.095
=> 744.095
irb(main):004:0> "%0.26f %0.26f" % [a, b]
=> "744.09499999999991359800333157 744.09500000000002728484105319"
See also: http://en.wikipedia.org/wiki/Floating_point
=end
- Status changed from Open to Rejected
=begin
OP is not a bug at all. We will consider about Float#to_s later.
Thank you for the info, Kurt.
=end
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0