Skip to content

Commit e485863

Browse files
committed
Fixed to avoid incorrect optimization with llvm15.0.0
1 parent b558a18 commit e485863

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ext/standard/math.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,22 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
187187
* e.g.
188188
* 0.285 * 10000000000 => 2850000000.0
189189
* floor(0.285 * 10000000000) => 2850000000
190+
*
191+
* Using `if` twice to prevent accidental optimization with llvm 15.0.0.
190192
*/
191193
cpu_round_mode = fegetround();
192194
if (value >= 0.0) {
193195
fesetround(FE_UPWARD);
194-
tmp_value = floor(places > 0 ? value * exponent : value / exponent);
195196
} else {
196197
fesetround(FE_DOWNWARD);
197-
tmp_value = ceil(places > 0 ? value * exponent : value / exponent);
198+
}
199+
200+
adjusted_value = places > 0 ? value * exponent : value / exponent;
201+
202+
if (value >= 0.0) {
203+
tmp_value = floor(adjusted_value);
204+
} else {
205+
tmp_value = ceil(adjusted_value);
198206
}
199207
fesetround(cpu_round_mode);
200208

0 commit comments

Comments
 (0)