Bug #78071 [Opn->Dup]: using 0.9 vs 0.90 gives different results with bcmul
| From: | cmb@php.net | Date: | Fri, 16 Jul 2021 12:51:43 +0000 |
| Subject: | Bug #78071 [Opn->Dup]: using 0.9 vs 0.90 gives different results with bcmul | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235081@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78071&edit=1
ID: 78071
Updated by: cmb@php.net
Reported by: terrafrost@php.net
Summary: using 0.9 vs 0.90 gives different results with bcmul
-Status: Open
+Status: Duplicate
Type: Bug
Package: BC math related
Operating System: any
PHP Version: 7.3.5
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
I'm closing this as duplicate of bug #78238.
Previous Comments:
------------------------------------------------------------------------
[2019-07-02 06:42:27] cmb@php.net
Related To: Bug #78238
------------------------------------------------------------------------
[2019-05-27 22:11:30] 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
-----------
------------------------------------------------------------------------
[2019-05-26 23:39:53] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78071&edit=1