Bug #79185 [NEW]: sum numbers expecting to return 0
| From: | marius dot veleanu at gmail dot com | Date: | Tue, 28 Jan 2020 18:29:56 +0000 |
| Subject: | Bug #79185 [NEW]: sum numbers expecting to return 0 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-225204@lists.php.net to get a copy of this message | ||
From: marius dot veleanu at gmail dot com
Operating system: macOS Catalina 10.15.2
PHP version: 7.3.14
Package: *General Issues
Bug Type: Bug
Bug description:sum numbers expecting to return 0
Description:
------------
the sum of the numbers (positive and negative) in a loop, is expected to
be 0
tested with:
PHP 7.3.12-1
PHP 7.0.33-0 (cli)
PHP 7.3.9 (cli)
Test script:
---------------
$arr = [1.9, 1.9, 1.9, -5.7]; or $arr = [1.9, 1.9, 1.9, 1.9, 1.9, 1.9,
1.9, 1.9, -15.2]; or $arr = [1.9, 1.9, 1.9, 1.9, 1.9, 1.9, 1.9, 1.9,
1.9, 1.9, 1.9, 1.9, -22.8];
echo array_sum($arr); //-8.8817841970013E-16 //1.7763568394003E-15
//-3.5527136788005E-15
AND same result with
$total = 0; foreach( $arr as $a ){ $total += $a; } echo $total; //
-8.8817841970013E-16 //1.7763568394003E-15 //-3.5527136788005E-15
BUT this works
$arr = [1.9, 1.9, -3.8]; //0
$arr = [1.9, 1.9, 1.9, 1.9, -7.6]; //0
$arr = [1.9, 1.9, 1.9, 1.9, 1.9, 1.9, 1.9, 1.9, 1.9, -17.1]; //0
--
Edit bug report at https://bugs.php.net/bug.php?id=79185&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79185&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79185&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79185&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79185&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79185&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79185&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79185&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79185&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79185&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79185&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79185&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79185&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79185&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79185&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79185&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79185&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79185&r=mysqlcfg