diff --git a/ext/standard/math.c b/ext/standard/math.c index 6b16b0755f69b..2f6743865b464 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -177,6 +177,10 @@ PHPAPI double _php_math_round(double value, int places, int mode) { return value; } + if (places == 0) { + return php_round_helper(value, mode); + } + places = places < INT_MIN+1 ? INT_MIN+1 : places; precision_places = 14 - php_intlog10abs(value); diff --git a/ext/standard/tests/math/round_gh12143_5.phpt b/ext/standard/tests/math/round_gh12143_5.phpt new file mode 100644 index 0000000000000..9f05628e5de84 --- /dev/null +++ b/ext/standard/tests/math/round_gh12143_5.phpt @@ -0,0 +1,27 @@ +--TEST-- +GH-12143: Test rounding of 1.4999999999999998. +--FILE-- + %+.17g\n", $mode, $number, round($number, 0, constant($mode))); + } +} +?> +--EXPECT-- +PHP_ROUND_HALF_UP : +1.4999999999999998 -> +1 +PHP_ROUND_HALF_DOWN : +1.4999999999999998 -> +1 +PHP_ROUND_HALF_EVEN : +1.4999999999999998 -> +1 +PHP_ROUND_HALF_ODD : +1.4999999999999998 -> +1 +PHP_ROUND_HALF_UP : -1.4999999999999998 -> -1 +PHP_ROUND_HALF_DOWN : -1.4999999999999998 -> -1 +PHP_ROUND_HALF_EVEN : -1.4999999999999998 -> -1 +PHP_ROUND_HALF_ODD : -1.4999999999999998 -> -1 diff --git a/ext/standard/tests/math/round_gh12143_6.phpt b/ext/standard/tests/math/round_gh12143_6.phpt new file mode 100644 index 0000000000000..07b1cc73ce615 --- /dev/null +++ b/ext/standard/tests/math/round_gh12143_6.phpt @@ -0,0 +1,27 @@ +--TEST-- +GH-12143: Test rounding of 4503599627370495.5. +--FILE-- + %+.17g\n", $mode, $number, round($number, 0, constant($mode))); + } +} +?> +--EXPECT-- +PHP_ROUND_HALF_UP : +4503599627370495.5 -> +4503599627370496 +PHP_ROUND_HALF_DOWN : +4503599627370495.5 -> +4503599627370495 +PHP_ROUND_HALF_EVEN : +4503599627370495.5 -> +4503599627370496 +PHP_ROUND_HALF_ODD : +4503599627370495.5 -> +4503599627370495 +PHP_ROUND_HALF_UP : -4503599627370495.5 -> -4503599627370496 +PHP_ROUND_HALF_DOWN : -4503599627370495.5 -> -4503599627370495 +PHP_ROUND_HALF_EVEN : -4503599627370495.5 -> -4503599627370496 +PHP_ROUND_HALF_ODD : -4503599627370495.5 -> -4503599627370495