Bug #922
closedFloat == is false when should be true
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
Updated by drbrain (Eric Hodel) almost 16 years ago
=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/922Author: Amanda Nicholas
Status: Open, Priority: Normal
Target version: Ruby 1.8.7In 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
Updated by daz (Dave B) almost 16 years ago
=begin
This might help, also:
http://whynotwiki.com/Ruby_/_Numbers#Comparing_Floating-Point_Numbers
=end
Updated by kstephens (Kurt Stephens) almost 16 years ago
=begin
Perhaps Ruby should do what Common Lisp implementations have been doing:
http://portal.acm.org/citation.cfm?id=989431
http://kurtstephens.com/files/p372-steele.pdf
ftp://netlib.bell-labs.com/netlib/fp/gdtoa.tgz
Perhaps the default Float#to_s formatting should not throw away necessary precision, so that:
some_float == eval("#{some_float}")
is always true.
=end
Updated by matz (Yukihiro Matsumoto) almost 16 years ago
- 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