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: 2021-07-16 12:51 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: terrafrost@php.net Assigned: cmb (profile)
Status: Duplicate Package: BC math related
PHP Version: 7.3.5 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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
-----------
 [2021-07-16 12:51 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2021-07-16 12:51 UTC] cmb@php.net
I'm closing this as duplicate of bug #78238.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC