Skip to content

Commit 709869c

Browse files
committed
ext/bcmath: Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0)
1 parent ce7ed6e commit 709869c

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ PHP NEWS
77
. Fixed bug GH-12814 (max_execution_time reached too early on MacOS 14
88
when running on Apple Silicon). (Manuel Kress)
99

10+
- BCMatch:
11+
. Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0). (Girgias)
12+
1013
- Curl:
1114
. Fixed bug GH-14307 (Test curl_basic_024 fails with curl 8.8.0). (nielsdos)
1215

ext/bcmath/libbcmath/src/raisemod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ zend_result bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, i
8181

8282
/* Do the calculation. */
8383
rscale = MAX(scale, power->n_scale);
84-
if ( !bc_compare(modulus, BCG(_one_)) )
84+
if ( !_bc_do_compare(modulus, BCG(_one_), false, false) )
8585
{
8686
bc_free_num (&temp);
8787
temp = bc_new_num (1, scale);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
bcpowmod() must return 0 when mod is +1 or -1
3+
--EXTENSIONS--
4+
bcmath
5+
--FILE--
6+
<?php
7+
var_dump(bcpowmod(5, 0, 1));
8+
var_dump(bcpowmod(5, 0, 1, 3));
9+
var_dump(bcpowmod(5, 0, -1));
10+
var_dump(bcpowmod(5, 0, -1, 3));
11+
?>
12+
--EXPECT--
13+
string(1) "0"
14+
string(5) "0.000"
15+
string(1) "0"
16+
string(5) "0.000"

0 commit comments

Comments
 (0)