php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76955 -1*round(0,2) = -0
Submitted: 2018-10-01 07:26 UTC Modified: 2018-10-01 08:06 UTC
From: giolaza at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.2.10 OS: Windows, Linux
Private report: No CVE-ID: None
 [2018-10-01 07:26 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-01 07:32 UTC] 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 08:06 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-10-01 08:06 UTC] cmb@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 07:01:29 2024 UTC