Bug #76955 [Opn->Nab]: -1*round(0,2) = -0

From: Date: Mon, 01 Oct 2018 08:06:19 +0000
Subject: Bug #76955 [Opn->Nab]: -1*round(0,2) = -0
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217338@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76955&edit=1 ID: 76955 Updated by: cmb@php.net Reported by: giolaza at gmail dot com Summary: -1*round(0,2) = -0 -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: Windows, Linux PHP Version: 7.2.10 -Assigned To: +Assigned To: cmb 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. A negative zero is to be expected here. Previous Comments: ------------------------------------------------------------------------ [2018-10-01 07:32:32] giolaza at gmail dot com $var= -1*0; var_dump($var); //int(0) var_dump($var==0); //bool(true) var_dump($var===0); //bool(true) $var= -1*0.00; var_dump($var); //float(-0) var_dump($var==0); //bool(true) var_dump($var===0); //bool(false) as we can see we had problem with float type ------------------------------------------------------------------------ [2018-10-01 07:26:14] giolaza at gmail dot com Description: ------------ -1*round(0) = -0 Test script: --------------- $var= -1*round(0,2); var_dump($var); //float(-0) var_dump($var==0); //bool(true) var_dump($var===0); //bool(false) $var= -1*round(0);//has same results Actual result: -------------- $var= -1*round(0,2); var_dump($var); //float(-0) var_dump($var==0); //bool(true) var_dump($var===0); //bool(false) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76955&edit=1

« previous php.bugs (#217338) next »