Skip to content

Feature GH-12143: Extend the maximum precision round can handle by one digit #12222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/standard/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
fesetround(cpu_round_mode);

/* This value is beyond our precision, so rounding it is pointless */
if (fabs(tmp_value) >= 1e15) {
if (fabs(tmp_value) >= 1e16) {
return value;
}

Expand Down
84 changes: 42 additions & 42 deletions ext/standard/tests/math/round_gh12143_expand-rounding-target.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -82,65 +82,65 @@ foreach ($testCases as $mode => $cases) {
?>
--EXPECT--
========== PHP_ROUND_HALF_UP ==========
float(0.12345678901234565)
float(-0.12345678901234565)
float(12345678901234564)
float(-12345678901234564)
float(4503599627370495.5)
float(-4503599627370495.5)
float(0.1234567890123457)
float(-0.1234567890123457)
float(12345678901234570)
float(-12345678901234570)
float(4503599627370496)
float(-4503599627370496)

========== PHP_ROUND_HALF_DOWN ==========
float(0.12345678901234565)
float(-0.12345678901234565)
float(12345678901234564)
float(-12345678901234564)
float(4503599627370495.5)
float(-4503599627370495.5)
float(0.1234567890123456)
float(-0.1234567890123456)
float(12345678901234560)
float(-12345678901234560)
float(4503599627370495)
float(-4503599627370495)

========== PHP_ROUND_HALF_EVEN ==========
float(0.12345678901234565)
float(-0.12345678901234565)
float(12345678901234564)
float(-12345678901234564)
float(4503599627370495.5)
float(-4503599627370495.5)
float(0.1234567890123456)
float(-0.1234567890123456)
float(12345678901234560)
float(-12345678901234560)
float(4503599627370496)
float(-4503599627370496)

========== PHP_ROUND_HALF_ODD ==========
float(0.12345678901234565)
float(-0.12345678901234565)
float(12345678901234564)
float(-12345678901234564)
float(4503599627370495.5)
float(-4503599627370495.5)
float(0.1234567890123457)
float(-0.1234567890123457)
float(12345678901234570)
float(-12345678901234570)
float(4503599627370495)
float(-4503599627370495)

========== PHP_ROUND_AWAY_FROM_ZERO ==========
float(0.1234567890123456)
float(-0.1234567890123456)
float(12345678901234568)
float(-12345678901234568)
float(4503599627370495.5)
float(-4503599627370495.5)
float(12345678901234570)
float(-12345678901234570)
float(4503599627370496)
float(-4503599627370496)

========== PHP_ROUND_TOWARD_ZERO ==========
float(0.12345678901234566)
float(-0.12345678901234566)
float(12345678901234564)
float(-12345678901234564)
float(4503599627370495.5)
float(-4503599627370495.5)
float(0.1234567890123456)
float(-0.1234567890123456)
float(12345678901234560)
float(-12345678901234560)
float(4503599627370495)
float(-4503599627370495)

========== PHP_ROUND_CEILING ==========
float(0.1234567890123456)
float(-0.1234567890123456)
float(12345678901234564)
float(-12345678901234564)
float(4503599627370495.5)
float(-4503599627370495.5)
float(12345678901234570)
float(-12345678901234560)
float(4503599627370496)
float(-4503599627370495)

========== PHP_ROUND_FLOOR ==========
float(0.1234567890123456)
float(-0.1234567890123456)
float(12345678901234564)
float(-12345678901234564)
float(4503599627370495.5)
float(-4503599627370495.5)
float(12345678901234560)
float(-12345678901234570)
float(4503599627370495)
float(-4503599627370496)