ext/bcmath: Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0)

This commit is contained in:
Gina Peter Banyard 2024-05-30 15:47:25 +01:00
parent ce7ed6e040
commit 709869c8bd
No known key found for this signature in database
GPG Key ID: 3306078E3194AEBD
3 changed files with 20 additions and 1 deletions

3
NEWS
View File

@ -7,6 +7,9 @@ PHP NEWS
. Fixed bug GH-12814 (max_execution_time reached too early on MacOS 14
when running on Apple Silicon). (Manuel Kress)
- BCMatch:
. Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0). (Girgias)
- Curl:
. Fixed bug GH-14307 (Test curl_basic_024 fails with curl 8.8.0). (nielsdos)

View File

@ -81,7 +81,7 @@ zend_result bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, i
/* Do the calculation. */
rscale = MAX(scale, power->n_scale);
if ( !bc_compare(modulus, BCG(_one_)) )
if ( !_bc_do_compare(modulus, BCG(_one_), false, false) )
{
bc_free_num (&temp);
temp = bc_new_num (1, scale);

View File

@ -0,0 +1,16 @@
--TEST--
bcpowmod() must return 0 when mod is +1 or -1
--EXTENSIONS--
bcmath
--FILE--
<?php
var_dump(bcpowmod(5, 0, 1));
var_dump(bcpowmod(5, 0, 1, 3));
var_dump(bcpowmod(5, 0, -1));
var_dump(bcpowmod(5, 0, -1, 3));
?>
--EXPECT--
string(1) "0"
string(5) "0.000"
string(1) "0"
string(5) "0.000"