Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/251347-32-bit-vs-64-bit-division-different/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.