summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/bcmath/libbcmath/src/str2num.c3
-rw-r--r--ext/bcmath/tests/bug46781.phpt16
2 files changed, 19 insertions, 0 deletions
diff --git a/ext/bcmath/libbcmath/src/str2num.c b/ext/bcmath/libbcmath/src/str2num.c
index ef505e86e1..62544de80e 100644
--- a/ext/bcmath/libbcmath/src/str2num.c
+++ b/ext/bcmath/libbcmath/src/str2num.c
@@ -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
index 0000000000..caffe83860
--- /dev/null
+++ b/ext/bcmath/tests/bug46781.phpt
@@ -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===