php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78071 using 0.9 vs 0.90 gives different results with bcmul
Submitted: 2019-05-26 23:39 UTC Modified: 2019-05-27 22:11 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: terrafrost@php.net Assigned:
Status: Open Package: BC math related
PHP Version: 7.3.5 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: terrafrost@php.net
New email:
PHP Version: OS:

 

 [2019-05-26 23:39 UTC] terrafrost@php.net
Description:
------------
One would expect 0.9 * -0.1 to yield the same result as 0.90 * -0.1, with BCMath, but alas, this does not appear to be the case.

Test script:
---------------
<?php

$a = bcmul('0.9', '-0.1', 1);
$b = bcmul('0.90', '-0.1', 1);

echo $a === $b ? 'same' : 'different';

echo "\n$a\n$b";

Expected result:
----------------
I would expect $a === $b to be true.

Actual result:
--------------
$a === $b is false. $a is 0.0, $b is -0.0.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-27 22:11 UTC] yohgaki@php.net
In order to compare bcmath values reliably, bccomp() should be used. i.e. Type could be juggled also.

https://3v4l.org/R1NrY

"-" in front of zero is not nice to have though.

BC behaves as follows and it seem a bit strange. i.e. scale=1 seems to work mostly, but not exactly.

-----------
$ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
scale=0
10/3
3
scale=1
10/3
3.3
0.9 * -0.1
0
0.90 * -0.1
-.09
-----------
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 05:01:25 2019 UTC