https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112010-05-11T20:30:36ZRuby Issue Tracking SystemRuby 1.8 - Backport #3273: Float string conversionhttps://bugs.ruby-lang.org/issues/3273?journal_id=109362010-05-11T20:30:36Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>2010/5/11 Marc-Andre Lafortune <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<p>For any float f, the two following conditions should hold:<br>
(1) f.to_s.to_f == f (round trips)<br>
(2) f.to_s.chop.to_f != f (minimal)</p>
<p>The second condition is a simplification; if the string representation is in scientific notation, than the character to remove would be the one just before the "e". Also, if the string representation ends with ".0", then it is minimal.</p>
</blockquote>
<p>Neat formulation.</p>
<blockquote>
<p>The fact is that 17 can be necessary (e.g. 0.21611564636388508 is not equal to either 0.2161156463638851 or 0.2161156463638850) and 16 can be too much (e.g. 0.5600000000000001 == 0.56), so three precisions must be checked.</p>
</blockquote>
<p>Interesting. 18 cannot be necessary, and 15 cannot be too much,<br>
so it is enough to try 15, 16 and 17 digits. Right?</p>
<blockquote>
<p>The following patch fixes this issue for trunk (although it can probably be made nicer and/or faster).</p>
</blockquote>
<p>Agreed.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p>
<p>=end</p> Ruby 1.8 - Backport #3273: Float string conversionhttps://bugs.ruby-lang.org/issues/3273?journal_id=109542010-05-12T02:51:37Zkstephens (Kurt Stephens)
<ul></ul><p>=begin<br>
Should Float#to_s cache its result since Floats are immutable values and Float#to_s is fairly complex/expensive?<br>
=end</p> Ruby 1.8 - Backport #3273: Float string conversionhttps://bugs.ruby-lang.org/issues/3273?journal_id=109582010-05-12T06:45:18Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>=begin<br>
Hi,</p>
<p>In message "Re: <a href="https://blade.ruby-lang.org/ruby-core/30165">[ruby-core:30165]</a> [Bug <a class="issue tracker-4 status-5 priority-4 priority-default closed" title="Backport: Float string conversion (Closed)" href="https://bugs.ruby-lang.org/issues/3273">#3273</a>] Float string conversion"<br>
on Wed, 12 May 2010 02:51:37 +0900, Kurt Stephens <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> writes:</p>
<p>|Should Float#to_s cache its result since Floats are immutable values and the Float#to_s is fairly complex/expensive?</p>
<p>First, Maybe. it should. But it's not a bug at least. Move to<br>
feature-request. Second, we need to prove the effectiveness of the<br>
caching in real-world use-case (is it really a bottleneck?), before<br>
sacrifying space efficiency.</p>
<pre><code> matz.
</code></pre>
<p>=end</p> Ruby 1.8 - Backport #3273: Float string conversionhttps://bugs.ruby-lang.org/issues/3273?journal_id=109652010-05-12T11:07:07Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>=begin<br>
This issue was solved with changeset r27745.<br>
Marc-Andre, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<p>=end</p> Ruby 1.8 - Backport #3273: Float string conversionhttps://bugs.ruby-lang.org/issues/3273?journal_id=109822010-05-12T23:42:09ZRickDeNatale (Rick DeNatale)rick.denatale@gmail.com
<ul></ul><p>=begin<br>
On Tue, May 11, 2010 at 5:44 PM, Yukihiro Matsumoto <a href="mailto:matz@ruby-lang.org" class="email">matz@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>Hi,</p>
<p>In message "Re: <a href="https://blade.ruby-lang.org/ruby-core/30165">[ruby-core:30165]</a> [Bug <a class="issue tracker-4 status-5 priority-4 priority-default closed" title="Backport: Float string conversion (Closed)" href="https://bugs.ruby-lang.org/issues/3273">#3273</a>] Float string conversion"<br>
on Wed, 12 May 2010 02:51:37 +0900, Kurt Stephens <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> writes:</p>
<p>|Should Float#to_s cache its result since Floats are immutable values and the Float#to_s is fairly complex/expensive?</p>
<p>First, Maybe. it should. But it's not a bug at least. Move to<br>
feature-request. Second, we need to prove the effectiveness of the<br>
caching in real-world use-case (is it really a bottleneck?), before<br>
sacrifying space efficiency.</p>
</blockquote>
<p>I'm not even sure how this would work.</p>
<p>Although floats ARE immutable they aren't interned, so it's unlikely<br>
that two computed float values which are equal will be the same<br>
object, so cacheing to_s for an instance of Float isn't likely to gain<br>
much. Caching through some kind of hash would seem to be the only<br>
other option, and that may be on the same order of performance as just<br>
recomputing the string, not sure just a guess. It would also hamper<br>
GC by keeping references, to the strings and float keys.</p>
<p>I'd also guess that this if this IS a problem it's only a problem for<br>
a small class of applications, and would be better addressed by those<br>
applications.</p>
<p>--<br>
Rick DeNatale</p>
<p>Blog: <a href="http://talklikeaduck.denhaven2.com/" class="external">http://talklikeaduck.denhaven2.com/</a><br>
Github: <a href="http://github.com/rubyredrick" class="external">http://github.com/rubyredrick</a><br>
Twitter: <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/386">@RickDeNatale (Rick DeNatale)</a><br>
WWR: <a href="http://www.workingwithrails.com/person/9021-rick-denatale" class="external">http://www.workingwithrails.com/person/9021-rick-denatale</a><br>
LinkedIn: <a href="http://www.linkedin.com/in/rickdenatale" class="external">http://www.linkedin.com/in/rickdenatale</a></p>
<p>=end</p> Ruby 1.8 - Backport #3273: Float string conversionhttps://bugs.ruby-lang.org/issues/3273?journal_id=113722010-05-30T21:08:01Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Status</strong> changed from <i>Closed</i> to <i>Open</i></li><li><strong>Assignee</strong> deleted (<del><i>marcandre (Marc-Andre Lafortune)</i></del>)</li><li><strong>Target version</strong> set to <i>Ruby 1.8.8</i></li></ul><p>=begin</p>
<p>=end</p> Ruby 1.8 - Backport #3273: Float string conversionhttps://bugs.ruby-lang.org/issues/3273?journal_id=272342012-06-14T11:30:45Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/27234/diff?detail_id=20204">diff</a>)</li><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul>