<?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: PHP vs. BIGINT vs. float conversion caveat</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:23:57 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Kr±g Starszoharcerski &#8220;Matrix&#8221; &#187; Blog Archive &#187; Jak nie należy obsługiwać dużych liczb</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-233028</link>
		<dc:creator>Kr±g Starszoharcerski &#8220;Matrix&#8221; &#187; Blog Archive &#187; Jak nie należy obsługiwać dużych liczb</dc:creator>
		<pubDate>Wed, 23 Jan 2008 07:42:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-233028</guid>
		<description></description>
		<content:encoded><![CDATA[<p>[...] przykład &#8211; PHP. Ten akurat problem mnie za bardzo nie dotyczył, ale to nie ¶wiadczy dobrze o PHP. Niestety, takich [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shodan</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-230390</link>
		<dc:creator>shodan</dc:creator>
		<pubDate>Sat, 12 Jan 2008 13:35:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-230390</guid>
		<description>Pierre,
thanks for the link, but the post point is a bit different: it&#039;s not about what you can use at this or that setup (there&#039;s plenty of extensions); it&#039;s only about the conversion issue you might run into.</description>
		<content:encoded><![CDATA[<p>Pierre,<br />
thanks for the link, but the post point is a bit different: it&#8217;s not about what you can use at this or that setup (there&#8217;s plenty of extensions); it&#8217;s only about the conversion issue you might run into.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-230300</link>
		<dc:creator>Pierre</dc:creator>
		<pubDate>Sat, 12 Jan 2008 09:24:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-230300</guid>
		<description>Try http://pecl.php.net/package/big_int

It is relatively fast (given that you have a php function call on each op). About php and large integers, it never supported anything else than 32bits integer. Whether the integer was stored in the system default integer (64bits on amd64 for example) did not change this problem. It is annoying but once you know it :)

I have something about this topic on my todo, to expose the openssl math functions. They are not the faster on earth but they can then be available by default (as almost all setup has openssl installed).</description>
		<content:encoded><![CDATA[<p>Try <a href="http://pecl.php.net/package/big_int" rel="nofollow">http://pecl.php.net/package/big_int</a></p>
<p>It is relatively fast (given that you have a php function call on each op). About php and large integers, it never supported anything else than 32bits integer. Whether the integer was stored in the system default integer (64bits on amd64 for example) did not change this problem. It is annoying but once you know it <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I have something about this topic on my todo, to expose the openssl math functions. They are not the faster on earth but they can then be available by default (as almost all setup has openssl installed).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Windows Update &#187; Comment on PHP vs. BIGINT vs. float conversion caveat by Windows&#8230;</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-230272</link>
		<dc:creator>Windows Update &#187; Comment on PHP vs. BIGINT vs. float conversion caveat by Windows&#8230;</dc:creator>
		<pubDate>Sat, 12 Jan 2008 07:35:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-230272</guid>
		<description>[...] MySQL Performance Blog wrote an interesting post today on Comment on PHP vs. BIGINT vs. float conversion caveat by Windows&#8230;Here&#8217;s a quick excerpt[â€¦] MySQL Performance Blog wrote an interesting post today on PHP vs. BIGINT vs. float conversion caveatHereâ€™s a quick excerpt Sometimes you need&#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] MySQL Performance Blog wrote an interesting post today on Comment on PHP vs. BIGINT vs. float conversion caveat by Windows&#8230;Here&#8217;s a quick excerpt[â€¦] MySQL Performance Blog wrote an interesting post today on PHP vs. BIGINT vs. float conversion caveatHereâ€™s a quick excerpt Sometimes you need&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Windows Update &#187; PHP vs. BIGINT vs. float conversion caveat</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-230149</link>
		<dc:creator>Windows Update &#187; PHP vs. BIGINT vs. float conversion caveat</dc:creator>
		<pubDate>Sat, 12 Jan 2008 03:25:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-230149</guid>
		<description>[...] MySQL Performance Blog wrote an interesting post today on PHP vs. BIGINT vs. float conversion caveatHere&#8217;s a quick excerpt Sometimes you need to work with big numbers in PHP (gulp). For example, sometimes 32-bit identifiers are not enough and you have to use BIGINT 64-bit ids; e.g. if you are encoding additional information like the server ID into high bits of the ID. I had already written about the mess that 64-bit integers are in PHP. But if the numbers you use do not cover 64-bit range fully, floats might save the day. The trick is that PHP floats are in fact doubles, i.e. double-precision 64-bit numbers. They [...]</description>
		<content:encoded><![CDATA[<p>[...] MySQL Performance Blog wrote an interesting post today on PHP vs. BIGINT vs. float conversion caveatHere&#8217;s a quick excerpt Sometimes you need to work with big numbers in PHP (gulp). For example, sometimes 32-bit identifiers are not enough and you have to use BIGINT 64-bit ids; e.g. if you are encoding additional information like the server ID into high bits of the ID. I had already written about the mess that 64-bit integers are in PHP. But if the numbers you use do not cover 64-bit range fully, floats might save the day. The trick is that PHP floats are in fact doubles, i.e. double-precision 64-bit numbers. They [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shodan</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-230099</link>
		<dc:creator>shodan</dc:creator>
		<pubDate>Fri, 11 Jan 2008 23:37:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-230099</guid>
		<description>Jakub,

you were right, it&#039;s the default settings of &quot;precision&quot; affecting this in ALL cases. Setting it to precision=16 (enough to hold 2^53 w/o sign) helps everywhere. The default values (both php.ini-dist and compiled-in) seems to vary but none of these reaches 16. I&#039;ll update the post.

It&#039;s not mentioned at php.net/float and the embedded description in php.ini-dist is, well, not quite clear (&quot;The number of significant digits displayed in floating point numbers&quot;). I believe it&#039;s kept at default 12 as most if not all sites.</description>
		<content:encoded><![CDATA[<p>Jakub,</p>
<p>you were right, it&#8217;s the default settings of &#8220;precision&#8221; affecting this in ALL cases. Setting it to precision=16 (enough to hold 2^53 w/o sign) helps everywhere. The default values (both php.ini-dist and compiled-in) seems to vary but none of these reaches 16. I&#8217;ll update the post.</p>
<p>It&#8217;s not mentioned at php.net/float and the embedded description in php.ini-dist is, well, not quite clear (&#8221;The number of significant digits displayed in floating point numbers&#8221;). I believe it&#8217;s kept at default 12 as most if not all sites.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-230096</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 11 Jan 2008 23:21:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-230096</guid>
		<description>Antony,

Regarding other libraries to deal with big numbers in PHP they have one serious issue - they are rather slow.
Sometimes it does not matter but sometimes it does.</description>
		<content:encoded><![CDATA[<p>Antony,</p>
<p>Regarding other libraries to deal with big numbers in PHP they have one serious issue &#8211; they are rather slow.<br />
Sometimes it does not matter but sometimes it does.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-230094</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 11 Jan 2008 23:19:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-230094</guid>
		<description>Thanks Andrew I&#039;ve now modified the comment.</description>
		<content:encoded><![CDATA[<p>Thanks Andrew I&#8217;ve now modified the comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shodan</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-230087</link>
		<dc:creator>shodan</dc:creator>
		<pubDate>Fri, 11 Jan 2008 22:48:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-230087</guid>
		<description>Antony,

&gt; First of all, I donâ€™t see any strings there.

Peter just made a typo. I explicitly mentioned conversion TO string, in bold.

&gt; in both cases float is expected to lose its precision 

No, it&#039;s not. It must not lose precision in THIS case. Refer to IEEE 754 section on 64-bit doubles (it&#039;s a bit more trusted source than php.net/float by the way). Doubles have 52 bits allocated for mantissa, which means that 52-bit (actually 53-bit) INTEGER values MUST be stored without ANY precision loss.

&gt; PHP tries to handle this in a crossplatform way

Even though it tries, it still fails. That failure is unexpected, and undocumented. For me, this is enough of a reason to make a blog post to warn the readers about such caveat.

&gt; To be honest, the whole issue described in this post looks kinda weird: isnâ€™t it obvious that you canâ€™t use 64bit integer values on 32bit platform without a special library/extension?

No, it isn&#039;t (other environments somehow manage to nicely support 64-bit values), but that&#039;s out of scope.

One should be able to manipulate 52-bit integer values stored as doubles without any precision loss. That actually works, and might be a perfectly valid solution in some scenarios. It&#039;s only the float to string conversion which suddenly, and unexpectedly, fails.</description>
		<content:encoded><![CDATA[<p>Antony,</p>
<p>> First of all, I donâ€™t see any strings there.</p>
<p>Peter just made a typo. I explicitly mentioned conversion TO string, in bold.</p>
<p>> in both cases float is expected to lose its precision </p>
<p>No, it&#8217;s not. It must not lose precision in THIS case. Refer to IEEE 754 section on 64-bit doubles (it&#8217;s a bit more trusted source than php.net/float by the way). Doubles have 52 bits allocated for mantissa, which means that 52-bit (actually 53-bit) INTEGER values MUST be stored without ANY precision loss.</p>
<p>> PHP tries to handle this in a crossplatform way</p>
<p>Even though it tries, it still fails. That failure is unexpected, and undocumented. For me, this is enough of a reason to make a blog post to warn the readers about such caveat.</p>
<p>> To be honest, the whole issue described in this post looks kinda weird: isnâ€™t it obvious that you canâ€™t use 64bit integer values on 32bit platform without a special library/extension?</p>
<p>No, it isn&#8217;t (other environments somehow manage to nicely support 64-bit values), but that&#8217;s out of scope.</p>
<p>One should be able to manipulate 52-bit integer values stored as doubles without any precision loss. That actually works, and might be a perfectly valid solution in some scenarios. It&#8217;s only the float to string conversion which suddenly, and unexpectedly, fails.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antony Dovgal</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/comment-page-1/#comment-230073</link>
		<dc:creator>Antony Dovgal</dc:creator>
		<pubDate>Fri, 11 Jan 2008 22:25:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/10/php-vs-bigint-vs-float-conversion-caveat/#comment-230073</guid>
		<description>Hello Peter.

&gt;However what Andrew is speaking about is completely different thing - conversion from string. 

First of all, I don&#039;t see any strings there.
I can see a float converted to a string in 2 different ways: using &quot;$var&quot; syntax and sprintf(&quot;%.0f&quot;).

Second, in both cases float is expected to lose its precision and the result you get is most likely different from the value it really holds, because that&#039;s the way floats work (surprise!).

And the third thing: even though PHP tries to handle this in a crossplatform way (because it uses its own float-to-string and string-to-float utilities since 5.2 or so, I don&#039;t remember exactly), the resulting value still depends on your system - compiler, CPU etc and may differ.

To be honest, the whole issue described in this post looks kinda weird: isn&#039;t it obvious that you can&#039;t use 64bit integer values on 32bit platform without a special library/extension?
There are at least 3 (three) extensions I know of designed especially for this purpose. 
Not enough for the author?

---

Oh, yeah, surely &quot;designers of PHP 5 (released in 2004) type system were either not aware of&quot; long long.
As well as designers of MySQL (released in 1995) never heard of Unicode (released in 1991), eh?</description>
		<content:encoded><![CDATA[<p>Hello Peter.</p>
<p>&gt;However what Andrew is speaking about is completely different thing &#8211; conversion from string. </p>
<p>First of all, I don&#8217;t see any strings there.<br />
I can see a float converted to a string in 2 different ways: using &#8220;$var&#8221; syntax and sprintf(&#8221;%.0f&#8221;).</p>
<p>Second, in both cases float is expected to lose its precision and the result you get is most likely different from the value it really holds, because that&#8217;s the way floats work (surprise!).</p>
<p>And the third thing: even though PHP tries to handle this in a crossplatform way (because it uses its own float-to-string and string-to-float utilities since 5.2 or so, I don&#8217;t remember exactly), the resulting value still depends on your system &#8211; compiler, CPU etc and may differ.</p>
<p>To be honest, the whole issue described in this post looks kinda weird: isn&#8217;t it obvious that you can&#8217;t use 64bit integer values on 32bit platform without a special library/extension?<br />
There are at least 3 (three) extensions I know of designed especially for this purpose.<br />
Not enough for the author?</p>
<p>&#8212;</p>
<p>Oh, yeah, surely &#8220;designers of PHP 5 (released in 2004) type system were either not aware of&#8221; long long.<br />
As well as designers of MySQL (released in 1995) never heard of Unicode (released in 1991), eh?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
