woodworks Posted November 18, 2011 Share Posted November 18, 2011 Trying to write a decimal to base-32 converter and ran into a strange problem. If I run this code: <?php $result = 657911351231 / 32; echo $result; ?> On a 32-bit machine the output is: 20559729725.969 On a 64-bit machine the output is: 20559729726 What gives? Why is the 32-bit system producing a more accurate result? How do I force PHP to return the more accurate result on the 64-bit machine? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/251347-32-bit-vs-64-bit-division-different/ Share on other sites More sharing options...
xyph Posted November 18, 2011 Share Posted November 18, 2011 Returns 20559729725.969 on 64-bit Win7. Quote Link to comment https://forums.phpfreaks.com/topic/251347-32-bit-vs-64-bit-division-different/#findComment-1289201 Share on other sites More sharing options...
Zane Posted November 18, 2011 Share Posted November 18, 2011 same here.. Quote Link to comment https://forums.phpfreaks.com/topic/251347-32-bit-vs-64-bit-division-different/#findComment-1289214 Share on other sites More sharing options...
woodworks Posted November 18, 2011 Author Share Posted November 18, 2011 Thanks for the responses. It must be something with older software/OS. The problem is occurring on an Ubuntu 8.0.4.4 LTS, 64-bit, server install. The problem does not occur on an Ubuntu 10.04.3 LTS, 64-bit, server installation. Quote Link to comment https://forums.phpfreaks.com/topic/251347-32-bit-vs-64-bit-division-different/#findComment-1289298 Share on other sites More sharing options...
Alex Posted November 18, 2011 Share Posted November 18, 2011 You could always use BCMath. Quote Link to comment https://forums.phpfreaks.com/topic/251347-32-bit-vs-64-bit-division-different/#findComment-1289358 Share on other sites More sharing options...
woodworks Posted November 19, 2011 Author Share Posted November 19, 2011 Turns out the bug has nothing to do with 32-bit vs 64-bit. It's a bug that was addressed in PHP 5.3. The system I am running it on is an old Ubuntu 8.04 server which has PHP 5.2 installed. Also, the bug is just a formatting issue caused by the conversion from float to string. Using printf to format the output instead of a simple echo will force PHP 5.2 to display the correct value. Quote Link to comment https://forums.phpfreaks.com/topic/251347-32-bit-vs-64-bit-division-different/#findComment-1289531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.