https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17097754782010-07-08T19:41:02ZRuby Issue Tracking SystemBackport187 - Backport #3550: Floating Point Representation Prevents Raising to Fractional Powerhttps://bugs.ruby-lang.org/issues/3550?journal_id=122292010-07-08T19:41:02ZEregon (Benoit Daloze)
<ul></ul><p>=begin<br>
On 8 July 2010 10:32, Milind Pandit <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>Backport <a class="issue tracker-4 status-5 priority-4 priority-default closed" title="Backport: Floating Point Representation Prevents Raising to Fractional Power (Closed)" href="https://bugs.ruby-lang.org/issues/3550">#3550</a>: Floating Point Representation Prevents Raising to Fractional Power<br>
<a href="http://redmine.ruby-lang.org/issues/show/3550" class="external">http://redmine.ruby-lang.org/issues/show/3550</a></p>
<p>Author: Milind Pandit<br>
Status: Open, Priority: Normal</p>
<p>Not sure why this literal float can be raised successfully to a fractional power, but when assigned to a variable, it returns NaN.</p>
<p>$ ruby --version<br>
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]<br>
$ irb<br>
-2.21792114695341 ** 0.1<br>
=> -1.08291560040828</p>
<blockquote>
<blockquote>
<p>-2.21792114695341 ** 1.1<br>
=> -2.40182141051126<br>
a = -2.21792114695341<br>
=> -2.21792114695341<br>
a ** 0.1<br>
=> NaN # Expected: -1.08291560040828<br>
a ** 1.1<br>
=> NaN # Expected: -2.40182141051126<br>
-2.21792114695341.to_f ** 1.1<br>
=> NaN # Expected: -1.08291560040828<br>
-2.21792114695341.to_f ** 0.1<br>
=> NaN # Expected: -2.40182141051126<br>
a - -2.21792114695341<br>
=> 0.0<br>
(a - -2.21792114695341).zero?<br>
=> true</p>
</blockquote>
</blockquote>
</blockquote>
<p>Because the answer is complex, and when you use both literal, the<br>
precedence of #** is higher than #-@</p>
<blockquote>
<p>(-2.21792114695341) ** 1.1<br>
=> NaN<br>
But<br>
-2.21792114695341 ** 1.1<br>
=> -2.40182141051126</p>
</blockquote>
<p>In 1.9, Complex are in the core and so:</p>
<blockquote>
<p>(-2.21792114695341) ** 1.1<br>
=> (-2.2842679034439537-0.742203633301588i)</p>
</blockquote>
<p>I believe it is possible in 1.8, but "require 'complex'" did not<br>
resolve this for me.</p>
<p>=end</p> Backport187 - Backport #3550: Floating Point Representation Prevents Raising to Fractional Powerhttps://bugs.ruby-lang.org/issues/3550?journal_id=795212019-07-15T16:07:18Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Backport</i></li><li><strong>Project</strong> changed from <i>Ruby 1.8</i> to <i>Backport187</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/79521/diff?detail_id=53050">diff</a>)</li><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul>