Bug #74665 [Opn->Nab]: Floats sum return quirk

From: Date: Sat, 27 May 2017 18:16:22 +0000
Subject: Bug #74665 [Opn->Nab]: Floats sum return quirk
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209282@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74665&edit=1 ID: 74665 Updated by: jhdxr@php.net Reported by: tomasz dot kane at gmail dot com Summary: Floats sum return quirk -Status: Open +Status: Not a bug Type: Bug Package: Variables related Operating System: Kubuntu PHP Version: 7.1.5 Block user comment: N Private report: N New Comment: Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://www.floating-point-gui.de/ Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2017-05-27 17:52:58] tomasz dot kane at gmail dot com Description: ------------ I'm just calculate array values sum. BTW I know about Floating point precision, but this result... Test script: --------------- $foo = [2.45, -1.05, -1.40]; echo array_sum($foo); // 2.2204460492503E-16 // same result when use foreach $sum += $item Expected result: ---------------- 0 Actual result: -------------- 2.2204460492503E-16 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74665&edit=1

« previous php.bugs (#209282) next »