Skip to content

Commit 447e642

Browse files
committed
Revert "Fixed to avoid incorrect optimization with llvm15.0.0"
This reverts commit 16d0394.
1 parent 16d0394 commit 447e642

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

ext/standard/math.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ static inline double php_round_helper(double integral, double value, double expo
163163
* mode. For the specifics of the algorithm, see http://wiki.php.net/rfc/rounding
164164
*/
165165
PHPAPI double _php_math_round(double value, int places, int mode) {
166-
double exponent, tmp_value, adjusted_value;
166+
double exponent;
167+
double tmp_value;
167168
int cpu_round_mode;
168169

169170
if (!zend_finite(value) || value == 0.0) {
@@ -186,23 +187,14 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
186187
* e.g.
187188
* 0.285 * 10000000000 => 2850000000.0
188189
* floor(0.285 * 10000000000) => 2850000000
189-
*
190-
* Using `if` twice to prevent accidental optimization with llvm 15.0.0.
191190
*/
192-
bool val_is_positive_or_zero = value >= 0.0;
193191
cpu_round_mode = fegetround();
194-
if (val_is_positive_or_zero) {
192+
if (value >= 0.0) {
195193
fesetround(FE_UPWARD);
194+
tmp_value = floor(places > 0 ? value * exponent : value / exponent);
196195
} else {
197196
fesetround(FE_DOWNWARD);
198-
}
199-
200-
adjusted_value = places > 0 ? value * exponent : value / exponent;
201-
202-
if (val_is_positive_or_zero) {
203-
tmp_value = floor(adjusted_value);
204-
} else {
205-
tmp_value = ceil(adjusted_value);
197+
tmp_value = ceil(places > 0 ? value * exponent : value / exponent);
206198
}
207199
fesetround(cpu_round_mode);
208200

0 commit comments

Comments
 (0)