<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Print Precision of Dyadic Fractions Varies by Language</title>
	<atom:link href="http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/</link>
	<description>Binary Numbers, Binary Code, and Binary Logic</description>
	<lastBuildDate>Mon, 06 Sep 2010 19:40:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Benjamin Rosseaux</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-4384</link>
		<dc:creator>Benjamin Rosseaux</dc:creator>
		<pubDate>Tue, 10 Aug 2010 16:51:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-4384</guid>
		<description>So you can download the ObjectPascal test program now from http://vserver.rosseaux.net/stuff/dyadic.zip (with full source code of the test program and my dtoa.c port pasDTOA.pas and two precompiled binaries, compiled with the two available ObjectPascal compilers, one compiled with FreePascal and one compiled with Delphi) to update your table top.</description>
		<content:encoded><![CDATA[<p>So you can download the ObjectPascal test program now from <a href="http://vserver.rosseaux.net/stuff/dyadic.zip" rel="nofollow">http://vserver.rosseaux.net/stuff/dyadic.zip</a> (with full source code of the test program and my dtoa.c port pasDTOA.pas and two precompiled binaries, compiled with the two available ObjectPascal compilers, one compiled with FreePascal and one compiled with Delphi) to update your table top.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Benjamin Rosseaux</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-4383</link>
		<dc:creator>Benjamin Rosseaux</dc:creator>
		<pubDate>Tue, 10 Aug 2010 16:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-4383</guid>
		<description>Oh ok, I&#039;ve overlook/miss it then. I&#039;ve updated my own ECMAscript 5th Edition implementation now (Sourceforge project BESEN), which allows a higher valid precision/digitwidth value range. :-) 

BESEN is implemented in ObjectPascal, so I&#039;ve ported&amp;with-own-features-enhanced the dtoa.c algorithms from C to ObjectPascal, and additionally to dtoa.c&#039;s strtod I&#039;ve wrote my own routine (which is based purely on arbitrary precision big integer operations without any FPU/SSE* operations) as second string-to-double-convert-routine, which give the exact results as dtoa.c&#039;s strtod, but works even on x64/AMD64 without SSE exceptions (because FreePascal generates on x64/AMD64 SSE* instruction instead of x87 FPU operartions and the floating point exception masking function in FreePascal isn&#039;t working correctly for SSE), so BESEN is using to ObjectPascal ported dtoa.c&#039;s strtod on the 32-bit x86 target and on all other non-x86/x64/AMD64 targets and my own routine on the x64/AMD64 target, and for double-to-string converts it uses always the ported dtoa function with some enhancments/modifications/fixes from me, due to security as heap/buffer overflows and so on.

And the original double-converting routines from FreePascal and Delphi are more or less on the precision level by Visual C++ from the table top. And if you can want, I can check it truely with test programs with FreePascal and Delphi.</description>
		<content:encoded><![CDATA[<p>Oh ok, I&#8217;ve overlook/miss it then. I&#8217;ve updated my own ECMAscript 5th Edition implementation now (Sourceforge project BESEN), which allows a higher valid precision/digitwidth value range. <img src='http://www.exploringbinary.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p>BESEN is implemented in ObjectPascal, so I&#8217;ve ported&amp;with-own-features-enhanced the dtoa.c algorithms from C to ObjectPascal, and additionally to dtoa.c&#8217;s strtod I&#8217;ve wrote my own routine (which is based purely on arbitrary precision big integer operations without any FPU/SSE* operations) as second string-to-double-convert-routine, which give the exact results as dtoa.c&#8217;s strtod, but works even on x64/AMD64 without SSE exceptions (because FreePascal generates on x64/AMD64 SSE* instruction instead of x87 FPU operartions and the floating point exception masking function in FreePascal isn&#8217;t working correctly for SSE), so BESEN is using to ObjectPascal ported dtoa.c&#8217;s strtod on the 32-bit x86 target and on all other non-x86/x64/AMD64 targets and my own routine on the x64/AMD64 target, and for double-to-string converts it uses always the ported dtoa function with some enhancments/modifications/fixes from me, due to security as heap/buffer overflows and so on.</p>
<p>And the original double-converting routines from FreePascal and Delphi are more or less on the precision level by Visual C++ from the table top. And if you can want, I can check it truely with test programs with FreePascal and Delphi.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Regan</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-4382</link>
		<dc:creator>Rick Regan</dc:creator>
		<pubDate>Tue, 10 Aug 2010 13:33:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-4382</guid>
		<description>Benjamin,

Thanks for the detailed comment.

I took a look at section 15.7.4.5 (p. 155). It also says this:

&lt;blockquote&gt;An implementation is permitted to extend the behaviour of toFixed for values of fractionDigits less than 0 or greater than 20. In this case toFixed would not necessarily throw RangeError for such values.&lt;/blockquote&gt;

You&#039;ll also note that, while JavaScript in IE does in fact limit the number of digits to 20, JavaScript in Firefox limits the number of digits to 100. (And I contend that, since 100 is OK, why not 1,074?)</description>
		<content:encoded><![CDATA[<p>Benjamin,</p>
<p>Thanks for the detailed comment.</p>
<p>I took a look at section 15.7.4.5 (p. 155). It also says this:</p>
<blockquote><p>An implementation is permitted to extend the behaviour of toFixed for values of fractionDigits less than 0 or greater than 20. In this case toFixed would not necessarily throw RangeError for such values.</p></blockquote>
<p>You&#8217;ll also note that, while JavaScript in IE does in fact limit the number of digits to 20, JavaScript in Firefox limits the number of digits to 100. (And I contend that, since 100 is OK, why not 1,074?)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Benjamin Rosseaux</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-4381</link>
		<dc:creator>Benjamin Rosseaux</dc:creator>
		<pubDate>Tue, 10 Aug 2010 12:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-4381</guid>
		<description>The ECMAScript spec (which JavaScript is based on) limits itself the methods toFixed etc. to a fixed &quot;valid&quot; precision/digitwidth value range. For example for toFixed, the ECMAscript 5th edition spec says: &quot;If f  20, throw a RangeError exception.&quot; in &quot;15.7.4.5 Number.prototype.toFixed (fractionDigits)&quot;  even if the engine uses dtoa.c or simliar good double-to-string routine implementation (like at my own ECMAscript 5th edition implementation BESEN) and could print plain technically more digits, bit the specification forbids it. For example my ECMAscript 5th edition implementation BESEN could technically the same precision/digitwidth range like GCC but due to the ECMAscript 5th edition specifications it is a range precheck there. Short: Sometimes are the too strict &quot;standardized&quot; language specifications itself the culprit for too low output precision and to less maximal output digit width.</description>
		<content:encoded><![CDATA[<p>The ECMAScript spec (which JavaScript is based on) limits itself the methods toFixed etc. to a fixed &#8220;valid&#8221; precision/digitwidth value range. For example for toFixed, the ECMAscript 5th edition spec says: &#8220;If f  20, throw a RangeError exception.&#8221; in &#8220;15.7.4.5 Number.prototype.toFixed (fractionDigits)&#8221;  even if the engine uses dtoa.c or simliar good double-to-string routine implementation (like at my own ECMAscript 5th edition implementation BESEN) and could print plain technically more digits, bit the specification forbids it. For example my ECMAscript 5th edition implementation BESEN could technically the same precision/digitwidth range like GCC but due to the ECMAscript 5th edition specifications it is a range precheck there. Short: Sometimes are the too strict &#8220;standardized&#8221; language specifications itself the culprit for too low output precision and to less maximal output digit width.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Regan</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-4274</link>
		<dc:creator>Rick Regan</dc:creator>
		<pubDate>Sun, 14 Feb 2010 20:43:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-4274</guid>
		<description>I updated the table (Windows only for now) to reflect Python 3.1 (thanks to Mark Dickinson) -- see http://www.exploringbinary.com/print-precision-of-floating-point-integers-varies-too/#comment-4273.</description>
		<content:encoded><![CDATA[<p>I updated the table (Windows only for now) to reflect Python 3.1 (thanks to Mark Dickinson) &#8212; see <a href="http://www.exploringbinary.com/print-precision-of-floating-point-integers-varies-too/#comment-4273" rel="nofollow">http://www.exploringbinary.com/print-precision-of-floating-point-integers-varies-too/#comment-4273</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Regan</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-1251</link>
		<dc:creator>Rick Regan</dc:creator>
		<pubDate>Thu, 30 Apr 2009 17:10:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-1251</guid>
		<description>Christophe,

  Since you mentioned it, I tried out bc and dc. Of course, they&#039;re arbitrary-precision calculators, so they should handle any value.

bc
==

bc
scale=2000
dyadic=2^-2000
dyadic

(prints out 2^-2000 accurately, a 2000 digit number, bigger than can fit in a double.)

dc
==

dc
(I pasted the 2000 digit 2^-1000 value here)
p
(prints out 2^-2000 accurately)</description>
		<content:encoded><![CDATA[<p>Christophe,</p>
<p>  Since you mentioned it, I tried out bc and dc. Of course, they&#8217;re arbitrary-precision calculators, so they should handle any value.</p>
<p>bc<br />
==</p>
<p>bc<br />
scale=2000<br />
dyadic=2^-2000<br />
dyadic</p>
<p>(prints out 2^-2000 accurately, a 2000 digit number, bigger than can fit in a double.)</p>
<p>dc<br />
==</p>
<p>dc<br />
(I pasted the 2000 digit 2^-1000 value here)<br />
p<br />
(prints out 2^-2000 accurately)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Regan</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-1248</link>
		<dc:creator>Rick Regan</dc:creator>
		<pubDate>Thu, 30 Apr 2009 14:34:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-1248</guid>
		<description>Kevin,

  I tried out serialize and unserialize -- you&#039;re right, there are similar limitations.

  2&lt;sup&gt;-143&lt;/sup&gt; is the smallest negative power of two that PHP can serialize. However, it can only &lt;em&gt;unserialize&lt;/em&gt; up to  2&lt;sup&gt;-40&lt;/sup&gt;!

  I will amend the bug report.

  Here are the testcases:

&lt;p class=&quot;break&quot;&gt;This code works -- it prints:
d:8.9683101716788292539118693330554632401936764280097009392452370
16894662929189507849514484405517578125E-44;  
&lt;/p&gt;
&lt;pre class=&quot;comments&quot;&gt;
&lt;?php
 //Serialize 2^-143
 $dyadic = //Compute as (2^-50)^2 * 2^-43 to break up
 0.00000000000000088817841970012523233890533447265625*
 0.00000000000000088817841970012523233890533447265625*
 0.0000000000001136868377216160297393798828125;
 echo serialize ($dyadic); 
?&gt;
&lt;/pre&gt;

&lt;p class=&quot;break&quot;&gt;This code fails -- it prints:
d:4.4841550858394146269559346665277316200968382140048504696226185
08447331464594753924757242202758789062E-44;
&lt;/p&gt;
&lt;pre&gt;
&lt;?php
 //Serialize 2^-144
 $dyadic = //Compute as (2^-50)^2 * 2^-44 to break up
 0.00000000000000088817841970012523233890533447265625*
 0.00000000000000088817841970012523233890533447265625*
 0.00000000000005684341886080801486968994140625;
 echo serialize ($dyadic); 
?&gt;
&lt;/pre&gt;

&lt;p class=&quot;break&quot;&gt;This code works -- it prints:
 0.0000000000009094947017729282379150390625
&lt;/p&gt;
&lt;pre&gt;
&lt;?php
 //Serialize and unserialize 2^-40
 $dyadic = 0.0000000000009094947017729282379150390625;
 printf (&quot;%1.40f&quot;,unserialize(serialize($dyadic)));
?&gt;
&lt;/pre&gt;

&lt;p class=&quot;break&quot;&gt;This code fails -- it prints: 
0.0000000000004547473508864641189575195312
&lt;/p&gt;
&lt;pre&gt;
&lt;?php
 //Serialize and unserialize 2^-41
 $dyadic = 0.00000000000045474735088646411895751953125;
 printf (&quot;%1.41f&quot;,unserialize(serialize($dyadic)));
?&gt;
&lt;/pre&gt;


(I did not try the ``largest fraction&#039;&#039; testcases but I&#039;d imagine they&#039;d have similar limitations.)</description>
		<content:encoded><![CDATA[<p>Kevin,</p>
<p>  I tried out serialize and unserialize &#8212; you&#8217;re right, there are similar limitations.</p>
<p>  2<sup>-143</sup> is the smallest negative power of two that PHP can serialize. However, it can only <em>unserialize</em> up to  2<sup>-40</sup>!</p>
<p>  I will amend the bug report.</p>
<p>  Here are the testcases:</p>
<p class="break">This code works &#8212; it prints:<br />
d:8.9683101716788292539118693330554632401936764280097009392452370<br />
16894662929189507849514484405517578125E-44;
</p>
<pre class="comments">
&lt;?php
 //Serialize 2^-143
 $dyadic = //Compute as (2^-50)^2 * 2^-43 to break up
 0.00000000000000088817841970012523233890533447265625*
 0.00000000000000088817841970012523233890533447265625*
 0.0000000000001136868377216160297393798828125;
 echo serialize ($dyadic);
?&gt;
</pre>
<p class="break">This code fails &#8212; it prints:<br />
d:4.4841550858394146269559346665277316200968382140048504696226185<br />
08447331464594753924757242202758789062E-44;
</p>
<pre>
&lt;?php
 //Serialize 2^-144
 $dyadic = //Compute as (2^-50)^2 * 2^-44 to break up
 0.00000000000000088817841970012523233890533447265625*
 0.00000000000000088817841970012523233890533447265625*
 0.00000000000005684341886080801486968994140625;
 echo serialize ($dyadic);
?&gt;
</pre>
<p class="break">This code works &#8212; it prints:<br />
 0.0000000000009094947017729282379150390625
</p>
<pre>
&lt;?php
 //Serialize and unserialize 2^-40
 $dyadic = 0.0000000000009094947017729282379150390625;
 printf (&quot;%1.40f&quot;,unserialize(serialize($dyadic)));
?&gt;
</pre>
<p class="break">This code fails &#8212; it prints:<br />
0.0000000000004547473508864641189575195312
</p>
<pre>
&lt;?php
 //Serialize and unserialize 2^-41
 $dyadic = 0.00000000000045474735088646411895751953125;
 printf (&quot;%1.41f&quot;,unserialize(serialize($dyadic)));
?&gt;
</pre>
<p>(I did not try the &#8220;largest fraction&#8221; testcases but I&#8217;d imagine they&#8217;d have similar limitations.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Gadd</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-1237</link>
		<dc:creator>Kevin Gadd</dc:creator>
		<pubDate>Thu, 30 Apr 2009 01:44:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-1237</guid>
		<description>If memory serves, PHP also has a hard-coded limit of 40 digits after the decimal place when serializing numbers using serialize().

This actually means that not only is precision lost when printing out doubles like the one you use in your example, but the precision may also be lost when serializing/unserializing them, which is painful.

This may have changed by now, though; I last researched it near the end of PHP4&#039;s lifetime. It was a surprise to me, to say the least (we were having weird issues with floating point numbers in some of our automated tests that turned out to be due to serialize()/unserialize().)</description>
		<content:encoded><![CDATA[<p>If memory serves, PHP also has a hard-coded limit of 40 digits after the decimal place when serializing numbers using serialize().</p>
<p>This actually means that not only is precision lost when printing out doubles like the one you use in your example, but the precision may also be lost when serializing/unserializing them, which is painful.</p>
<p>This may have changed by now, though; I last researched it near the end of PHP4&#8242;s lifetime. It was a surprise to me, to say the least (we were having weird issues with floating point numbers in some of our automated tests that turned out to be due to serialize()/unserialize().)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christophe Poucet</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-1228</link>
		<dc:creator>Christophe Poucet</dc:creator>
		<pubDate>Wed, 29 Apr 2009 13:34:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-1228</guid>
		<description>Don&#039;t forget dc and bc :).</description>
		<content:encoded><![CDATA[<p>Don&#8217;t forget dc and bc <img src='http://www.exploringbinary.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Regan</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-1225</link>
		<dc:creator>Rick Regan</dc:creator>
		<pubDate>Wed, 29 Apr 2009 12:21:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-1225</guid>
		<description>Hi Rasmus,
 
  Thanks for taking the time to comment.
 
   I tried changing php.ini as you suggested and I saw no difference.

   In the PHP source, in \ext\standard\formatted_print.c, there is this line of code: #define MAX_FLOAT_PRECISION 40. I&#039;ve been assuming this was the culprit.

P.S. Thanks for reopening the &lt;a title=&quot;See PHP bug report &#8220;printf of floating point variable prints maximum of 40 decimal places&#8221;&quot; href=&quot;http://bugs.php.net/bug.php?id=47168&quot; rel=&quot;nofollow&quot;&gt;PHP bug&lt;/a&gt;!</description>
		<content:encoded><![CDATA[<p>Hi Rasmus,</p>
<p>  Thanks for taking the time to comment.</p>
<p>   I tried changing php.ini as you suggested and I saw no difference.</p>
<p>   In the PHP source, in \ext\standard\formatted_print.c, there is this line of code: #define MAX_FLOAT_PRECISION 40. I&#8217;ve been assuming this was the culprit.</p>
<p>P.S. Thanks for reopening the <a title="See PHP bug report &ldquo;printf of floating point variable prints maximum of 40 decimal places&rdquo;" href="http://bugs.php.net/bug.php?id=47168" rel="nofollow">PHP bug</a>!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rasmus</title>
		<link>http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/comment-page-1/#comment-1203</link>
		<dc:creator>Rasmus</dc:creator>
		<pubDate>Tue, 28 Apr 2009 22:03:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.exploringbinary.com/?p=210#comment-1203</guid>
		<description>This is actually configurable in PHP.  In your php.ini file, try this:

precision=1024

and run your PHP tests again.</description>
		<content:encoded><![CDATA[<p>This is actually configurable in PHP.  In your php.ini file, try this:</p>
<p>precision=1024</p>
<p>and run your PHP tests again.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
