{"id":603,"date":"2011-01-06T10:33:37","date_gmt":"2011-01-06T14:33:37","guid":{"rendered":"http:\/\/www.timelordz.com\/blog\/?p=603"},"modified":"2011-01-22T11:56:38","modified_gmt":"2011-01-22T15:56:38","slug":"php-bug-53632-floating-point-arithmetic-issue-and-solutions","status":"publish","type":"post","link":"https:\/\/www.timelordz.com\/blog\/2011\/01\/php-bug-53632-floating-point-arithmetic-issue-and-solutions\/","title":{"rendered":"PHP Bug 53632 Floating Point Arithmetic Issue and Solutions"},"content":{"rendered":"<p>Today the above <a title=\"PHP Bug\" href=\"http:\/\/bugs.php.net\/bug.php?id=53632\" target=\"_blank\">PHP bug<\/a> was pointed out to me, and in looking into it further I discovered a few interesting things, which I&#8217;ve decided to list here.\u00a0 While this bug is serious, a bit of research quickly showed it requires a rather specific combination of PHP version, OS architecture and CPU architecture and feature set, as well as PHP build options.<\/p>\n<p>1) This is completely dependent on an x87 FPU design flaw, wherein 80-bit FP arithmetic is used.<\/p>\n<p>2) Newer processors (x86-64)\u00a0 with\u00a0 SSE2 are IEEE-754 compliant, and use 64-bit FP.\u00a0 So, even if you are running an affected version of PHP (5.3.x or 5.2.x) on a 32-bit OS, if you have an X86-64 CPU you may not in fact be affected (depending on how php was built). Test and see by running a simple test such as:<\/p>\n<p><span style=\"color: #00ccff;\">[user@host ~]$ cat phptest.php <br \/>\n &lt;?php $d = 2.2250738585072011e-308; echo $d + 0; echo &#8220;\\n&#8221;; ?&gt;<br \/>\n [user@host ~]$ php phptest.php <br \/>\n 2.2250738585072E-308<\/span><\/p>\n<p>3) One work around, if you are affected, is to simple have php.ini preload a simple\u00a0 script to detect to handle requests containing the problematic value, as described <a href=\"http:\/\/stackoverflow.com\/questions\/4610651\/any-problems-with-the-following-work-around-for-php-bug-53632\" target=\"_blank\">here<\/a>.<\/p>\n<p>4) Alternatively, if you wish to compile your own PHP, adding -mfpmath=sse (or \ufeff-ffloat-store) to your CFLAGS will also resolve this issue.<\/p>\n<p>While at first this bug may cause a sense that great effort will be needed on a sys admins part to update PHP on many servers, investigation and testing may show that little needs to be done. Of course, new packages for PHP 5.3 will soon be available with will correct the issue as well, but the above may assist you in assessing what actions may need to be taken in the interim.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today the above PHP bug was pointed out to me, and in looking into it further I discovered a few interesting things, which I&#8217;ve decided to list here.\u00a0 While this bug is serious, a bit of research quickly showed it requires a rather specific combination of PHP version, OS architecture and CPU architecture and feature [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[66,65],"class_list":["post-603","post","type-post","status-publish","format-standard","hentry","category-linux","tag-8-bit-fp","tag-php-bug-53632"],"_links":{"self":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts\/603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/comments?post=603"}],"version-history":[{"count":4,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts\/603\/revisions"}],"predecessor-version":[{"id":605,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts\/603\/revisions\/605"}],"wp:attachment":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/media?parent=603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/categories?post=603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/tags?post=603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}