bcmod() no longer truncates fractionals to integers. This matches
the behavior of fmod(). It also matches the behavior of bcpowmod().
It also matches the behavior of bcmod() in HHVM.
This commit is contained in:
Libor M 2015-10-17 08:09:16 +02:00 committed by Nikita Popov
parent 00062d2ea8
commit 90dcbbe3cb
4 changed files with 17 additions and 5 deletions

9
NEWS
View File

@ -2,9 +2,6 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 7.2
- Calendar:
. Fix integer overflows (Joshua Rogers)
- Core:
. Removed IS_TYPE_IMMUTABLE (it's the same as COPYABLE & !REFCOUNTED). (Dmitry)
. Removed the sql.safe_mode directive. (Kalle)
@ -26,6 +23,12 @@ PHP NEWS
. Raised minimum supported Windows versions to Windows 7/Server 2008 R2.
(Anatol)
- BCMath:
. Fixed bug #46564 (bcmod truncates fractionals). (liborm85)
- Calendar:
. Fix integer overflows (Joshua Rogers)
- Date:
. Fixed bug #69587 (DateInterval properties and isset). (jhdxr)

View File

@ -37,6 +37,11 @@ PHP 7.2 UPGRADE NOTES
property names would become inaccessible string keys.
. Minimum supported Windows versions are Windows 7/Server 2008 R2.
- BCMath:
. The bcmod() function no longer truncates fractional numbers to integers. As
such, its behavior now follows fmod() rather than the `%` operator. For
example `bcmod('4', '3.5')` now returns '0.5' instead of '1'.
- PCRE:
. preg_match() and other PCRE functions now distinguish between unmatched
subpatterns and empty matches by reporting NULL and "" (empty string),

View File

@ -403,8 +403,8 @@ PHP_FUNCTION(bcmod)
bc_init_num(&first);
bc_init_num(&second);
bc_init_num(&result);
bc_str2num(&first, ZSTR_VAL(left), 0);
bc_str2num(&second, ZSTR_VAL(right), 0);
php_str2num(&first, ZSTR_VAL(left));
php_str2num(&second, ZSTR_VAL(right));
switch (bc_modulo(first, second, &result, 0)) {
case 0:

View File

@ -9,8 +9,12 @@ bcmath.scale=0
echo bcmod("11", "2"),"\n";
echo bcmod("-1", "5"),"\n";
echo bcmod("8728932001983192837219398127471", "1928372132132819737213"),"\n";
echo bcmod("3.5", "4"),"\n";
echo bcmod("1071", "357.5"),"\n";
?>
--EXPECT--
1
-1
1459434331351930289678
3.5
356.0