[php-src] PHP-8.4: ext/standard Fix round() for large integral doubles (#22461)
| From: | arshidkv12 via Saki Takamachi | Date: | Sat, 05 Sep 2026 01:46:31 +0000 |
| Subject: | [php-src] PHP-8.4: ext/standard Fix round() for large integral doubles (#22461) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141075@lists.php.net to get a copy of this message | ||
Author: arshidkv12 (arshidkv12)
Committer: Saki Takamachi (SakiTakamachi)
Date: 2026-09-05T10:43:37+09:00
Commit: https://github.com/php/php-src/commit/c54c15c25ca2cfe041c165faad5c131530476842
Raw diff: https://github.com/php/php-src/commit/c54c15c25ca2cfe041c165faad5c131530476842.diff
ext/standard Fix round() for large integral doubles (#22461)
Closes #22461
Closes #22411
Fixes #22410
Changed paths:
A ext/standard/tests/math/gh22410.phpt
M NEWS
M ext/standard/math.c
Diff:
diff --git a/NEWS b/NEWS
index 1e917d3f01c9..b2e8d22465bf 100644
--- a/NEWS
+++ b/NEWS
@@ -100,6 +100,8 @@ PHP NEWS
. Fixed a memory leak in array_merge_recursive() when the recursive merge of
an object converted to an array fails. (David Carlier)
. Fixed read buffer compaction in php_stream_filter_flush(). (crystarm)
+ . Fixed bug GH-22410 (Incorrect float behavior with large numbers).
+ (arshidkv12)
- SimpleXML:
. Fixed writing to a dimension of the object returned by attributes() not
diff --git a/ext/standard/math.c b/ext/standard/math.c
index 758b352f90ff..09d982981043 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -172,6 +172,10 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
return value;
}
+ if (places == 0 && value == trunc(value)) {
+ return value;
+ }
+
places = places < INT_MIN+1 ? INT_MIN+1 : places;
exponent = php_intpow10(abs(places));
diff --git a/ext/standard/tests/math/gh22410.phpt b/ext/standard/tests/math/gh22410.phpt
new file mode 100644
index 000000000000..db2e92c3e6d9
--- /dev/null
+++ b/ext/standard/tests/math/gh22410.phpt
@@ -0,0 +1,14 @@
+--TEST--
+gh-22410: round() preserves integral doubles
+--FILE--
+<?php
+var_dump(round(1.0));
+var_dump(round(-1.0));
+var_dump(round((float) 9003241321073828));
+var_dump(round((float) -9003241321073828));
+?>
+--EXPECT--
+float(1)
+float(-1)
+float(9003241321073828)
+float(-9003241321073828)