Skip to content

Commit f939b97

Browse files
committed
Improved handling of adjusting result digits
1 parent 7c4db15 commit f939b97

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

ext/standard/math.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
148148
} else {
149149
tmp_value = value / f2;
150150
}
151-
/* preround the result (tmp_value will always be something * 1e14,
151+
/* adjust result digits (tmp_value will always be something * 1e14,
152152
thus never larger than 1e15 here) */
153-
tmp_value = php_round_helper(tmp_value, mode);
153+
tmp_value = (tmp_value >= 0.0) ? floor(tmp_value) : ceil(tmp_value);
154154

155155
use_precision = places - precision_places;
156156
use_precision = use_precision < INT_MIN+1 ? INT_MIN+1 : use_precision;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Fix GH-12143: Improved handling of adjusting result digits
3+
--FILE--
4+
<?php
5+
var_dump(round(1.700000000000145, 13, PHP_ROUND_HALF_UP));
6+
var_dump(round(-1.700000000000145, 13, PHP_ROUND_HALF_UP));
7+
?>
8+
--EXPECT--
9+
float(1.7000000000001)
10+
float(-1.7000000000001)

0 commit comments

Comments
 (0)