Bug #76810 [NEW]: Binary difference between numbers

From: Date: Wed, 29 Aug 2018 14:36:04 +0000
Subject: Bug #76810 [NEW]: Binary difference between numbers
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216782@lists.php.net to get a copy of this message
From:             joos at frisbee dot nl
Operating system: Windows / Linux
PHP version:      5.6.37
Package:          *General Issues
Bug Type:         Bug
Bug description:Binary difference between numbers

Description:
------------
If you execute the test script there is a difference in the binary
representation:

The first line will output: cdcccccccccc2640
The second line will output: cccccccccccc2640

The string representation both show 11.4.
The comparison will say that the result of the first line is higher than
the second line.
But that is not true, they should be equal.

This only seems to happen when you use 0.95 or 0.951.
If you use 0.9511 or 0.94 the result is as expected (if you recalculate
the expected result).
If you use 0.951 the result is the same as with 0.95.

This has been tested on both 5.6.37 and 7.1.21.

Test script:
---------------
var_dump(bin2hex(pack('d', 11.4)));
var_dump(bin2hex(pack('d', 0.95*12)));

if(11.4 > 0.95*12)
{
   echo 'It\'s bigger';
}
else
{
   echo 'It\'s the same or lower';//Should echo this, but it will echo
It's bigger
}

Expected result:
----------------
It's the same or lower should be echo-ed.

Actual result:
--------------
It's bigger will be echo-ed

-- 
Edit bug report at https://bugs.php.net/bug.php?id=76810&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=76810&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=76810&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=76810&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=76810&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=76810&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=76810&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=76810&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=76810&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=76810&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=76810&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=76810&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=76810&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=76810&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76810&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=76810&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=76810&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=76810&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76810&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=76810&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=76810&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#216782) next »