|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-01-28 19:53 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2020-01-28 19:53 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 06:00:01 2025 UTC |
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