https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112008-12-23T13:20:43ZRuby Issue Tracking SystemRuby 1.8 - Bug #922: Float == is false when should be truehttps://bugs.ruby-lang.org/issues/922?journal_id=22692008-12-23T13:20:43Zdrbrain (Eric Hodel)drbrain@segment7.net
<ul></ul><p>=begin<br>
On Dec 22, 2008, at 19:55 PM, Amanda Nicholas wrote:</p>
<blockquote>
<p>Bug <a class="issue tracker-1 status-6 priority-4 priority-default closed" title="Bug: Float == is false when should be true (Rejected)" href="https://bugs.ruby-lang.org/issues/922">#922</a>: Float == is false when should be true<br>
<a href="http://redmine.ruby-lang.org/issues/show/922" class="external">http://redmine.ruby-lang.org/issues/show/922</a></p>
<p>Author: Amanda Nicholas<br>
Status: Open, Priority: Normal<br>
Target version: Ruby 1.8.7</p>
<p>In irb on Ruby 1.8.6 (ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-<br>
linux]) and 1.8.7 (ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux])</p>
<blockquote>
<blockquote>
<p>896.5 * 0.83<br>
=> 744.095<br>
896.5 * 0.83 == 744.095<br>
=> false</p>
</blockquote>
</blockquote>
</blockquote>
<p>They're not the same, Ruby truncates the true value for display<br>
purposes:</p>
<p>irb(main):001:0> a = 896.5* 0.83<br>
=> 744.095<br>
irb(main):002:0> b = 744.095<br>
=> 744.095<br>
irb(main):004:0> "%0.26f %0.26f" % [a, b]<br>
=> "744.09499999999991359800333157 744.09500000000002728484105319"</p>
<p>See also: <a href="http://en.wikipedia.org/wiki/Floating_point" class="external">http://en.wikipedia.org/wiki/Floating_point</a></p>
<p>=end</p> Ruby 1.8 - Bug #922: Float == is false when should be truehttps://bugs.ruby-lang.org/issues/922?journal_id=22702008-12-23T13:33:11Zdaz (Dave B)
<ul></ul><p>=begin<br>
This might help, also:<br>
<a href="http://whynotwiki.com/Ruby_/_Numbers#Comparing_Floating-Point_Numbers" class="external">http://whynotwiki.com/Ruby_/_Numbers#Comparing_Floating-Point_Numbers</a></p>
<p>=end</p> Ruby 1.8 - Bug #922: Float == is false when should be truehttps://bugs.ruby-lang.org/issues/922?journal_id=22722008-12-23T13:57:11Zkstephens (Kurt Stephens)
<ul></ul><p>=begin<br>
Perhaps Ruby should do what Common Lisp implementations have been doing:</p>
<p><a href="http://portal.acm.org/citation.cfm?id=989431" class="external">http://portal.acm.org/citation.cfm?id=989431</a><br>
<a href="http://kurtstephens.com/files/p372-steele.pdf" class="external">http://kurtstephens.com/files/p372-steele.pdf</a><br>
<a href="ftp://netlib.bell-labs.com/netlib/fp/gdtoa.tgz" class="external">ftp://netlib.bell-labs.com/netlib/fp/gdtoa.tgz</a></p>
<p>Perhaps the default Float#to_s formatting should not throw away necessary precision, so that:</p>
<p>some_float == eval("#{some_float}")</p>
<p>is always true.</p>
<p>=end</p> Ruby 1.8 - Bug #922: Float == is false when should be truehttps://bugs.ruby-lang.org/issues/922?journal_id=22862008-12-23T23:52:34Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>=begin<br>
OP is not a bug at all. We will consider about Float#to_s later.<br>
Thank you for the info, Kurt.</p>
<p>=end</p>