]> granicus.if.org Git - php/commitdiff
Fixed bug #46564
authorLibor M <liborm85@gmail.com>
Sat, 17 Oct 2015 06:09:16 +0000 (08:09 +0200)
committerNikita Popov <nikic@php.net>
Sat, 7 Jan 2017 18:10:31 +0000 (19:10 +0100)
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.

NEWS
UPGRADING
ext/bcmath/bcmath.c
ext/bcmath/tests/bcmod.phpt

diff --git a/NEWS b/NEWS
index a9f9211e41b117f0d029cd0a015915507893e552..cc1bd152172a4ff74531676da9af4a493ec7b77c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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)
 
index b3c1d19aa09169dbdf31ce166bf52b753f6a5e5c..7766d4e363b0590ee41e4b1dfcea771b99793423 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -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),
index 300d88b86d06ee9f8f299554655a005e0c7860b1..e8b87dceff00e72e1cf7b8542d736f7570513ca7 100644 (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:
index 1d7be48a754b2dcdc436e6e5b1b8c6f389b5345a..5657e02ddc0f03a9506ae0e65da9c1f9e07b7379 100644 (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