]> granicus.if.org Git - php/commitdiff
Fixed bug #46781 (BC math handles minus zero incorrectly)
authorChristoph M. Becker <cmbecker69@gmx.de>
Mon, 11 Sep 2017 21:44:23 +0000 (23:44 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 11 Sep 2017 21:44:23 +0000 (23:44 +0200)
Actually, there is no negative zero at all.  We obey Postel's law, and
still accept negative zeroes, but we store them as positive zeroes
after the conversion from string, i.e. we normalize before further
processing.

NEWS
ext/bcmath/libbcmath/src/str2num.c
ext/bcmath/tests/bug46781.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 12c5003acc5f7d3680ecc1dd89d915188c4942bd..a866e5c8b35116d627b3c40bb8134baa2eb7832a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ PHP                                                                        NEWS
 
 - BCMath:
   . Fixed bug #44995 (bcpowmod() fails if scale != 0). (cmb)
+  . Fixed bug #46781 (BC math handles minus zero incorrectly). (cmb)
   . Fixed bug #54598 (bcpowmod() may return 1 if modulus is 1). (okano1220, cmb)
   . Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus). (cmb)
 
index ef505e86e1567fc42c739f4ee44d4312f14245c7..62544de80ec9fe9c8062d2fbed336dd617b1b3cb 100644 (file)
@@ -105,5 +105,8 @@ bc_str2num (bc_num *num, char *str, int scale)
       for (;strscale > 0; strscale--)
        *nptr++ = CH_VAL(*ptr++);
     }
+
+  if (bc_is_zero (*num))
+    (*num)->n_sign = PLUS;
 }
 
diff --git a/ext/bcmath/tests/bug46781.phpt b/ext/bcmath/tests/bug46781.phpt
new file mode 100644 (file)
index 0000000..caffe83
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Bug #46781 (BC math handles minus zero incorrectly)
+--SKIPIF--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension is not available');
+?>
+--FILE--
+<?php
+var_dump(bcadd('-0.0', '-0.0', 1));
+var_dump(bccomp('-0.0', '0', 1));
+?>
+===DONE===
+--EXPECT--
+string(3) "0.0"
+int(0)
+===DONE===