php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49947 Looks like overlow
Submitted: 2009-10-21 17:29 UTC Modified: 2009-10-21 20:39 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: haochen at pristineprinting dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.11 OS: CentOS 5.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
10 + 44 = ?
Subscribe to this entry?

 
 [2009-10-21 17:29 UTC] haochen at pristineprinting dot com
Description:
------------
It looks like overflow when I do plus 1. But when I do tims 2, it looks correct. Strange! I guess times and division move left or right for binery number(...1011101...). Plus and minus functions maybe have bugs? I don't know my code is wrong or it is a bug.

Server is Centos 5.3+PHP 5.2.11+Apache = Web Server
I just put this code into public_html

And client is WinXP+SP3+IE7. IE open the php. Wrong result.

Thanks a lot.

Reproduce code:
---------------
<?php
$x=2;
$p=100;
$y=pow($x,$p);
$a=number_format($y);
$b=$y+2;
$c=$y*2;
$r=number_format($a);
$rr=number_format($b);
echo "pow($x,$p)   = $a <br><br>";
echo "pow($x,$p)+2 = $r <br><br>";
echo "pow($x,$p)*2 = $rr <br><br>";
?>

Expected result:
----------------
pow(2,100)   = 1,267,650,600,228,229,401,496,703,205,376 

pow(2,100)+2 = 1,267,650,600,228,229,401,496,703,205,378 

pow(2,100)*2 = 2,535,301,200,456,458,802,993,406,410,752 


Actual result:
--------------
pow(2,100)   = 1,267,650,600,228,229,401,496,703,205,376 

pow(2,100)+2 = 1,267,650,600,228,229,401,496,703,205,376 

pow(2,100)*2 = 2,535,301,200,456,458,802,993,406,410,752 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-21 18:09 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

pow(2,100)+2  will be converted to a float, and floats aren't precise.
 [2009-10-21 18:59 UTC] haochen at pristineprinting dot com
Thanks for your quick response.

You are right. I tested in Java and ASP, they lost more precise than PHP.

Do you think it is 32-bit system limition or current-generation computer limition?

If my server is AIX, the result will be correct or not?

Anyway, thanks for your answer again. :-)
 [2009-10-21 20:39 UTC] johannes@php.net
All "recent" machines should follow the IEEE 754 standard, but I know nothing about AIX.

http://en.wikipedia.org/wiki/IEEE_754-2008
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 01:01:28 2024 UTC