Bug #78071 [Opn]: using 0.9 vs 0.90 gives different results with bcmul

From: Date: Mon, 27 May 2019 22:11:30 +0000
Subject: Bug #78071 [Opn]: 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-221021@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: yohgaki@php.net Reported by: terrafrost@php.net Summary: using 0.9 vs 0.90 gives different results with bcmul Status: Open Type: Bug Package: BC math related Operating System: any PHP Version: 7.3.5 Block user comment: N Private report: N New Comment: 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 ----------- Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#221021) next »