Skip to content

Commit 711bc54

Browse files
committed
Improved handling of adjusting result digits
1 parent 748adf1 commit 711bc54

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
@@ -149,9 +149,9 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
149149
} else {
150150
tmp_value = value / f2;
151151
}
152-
/* preround the result (tmp_value will always be something * 1e14,
152+
/* adjust result digits (tmp_value will always be something * 1e14,
153153
thus never larger than 1e15 here) */
154-
tmp_value = php_round_helper(tmp_value, mode);
154+
tmp_value = (tmp_value >= 0.0) ? floor(tmp_value) : ceil(tmp_value);
155155

156156
use_precision = places - precision_places;
157157
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)