Skip to content

Commit 0faa198

Browse files
committed
optimized round() processing
1 parent a8b422c commit 0faa198

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

ext/standard/math.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,10 @@ static inline double php_intpow10(int power) {
4949
/* {{{ php_round_helper
5050
Actually performs the rounding of a value to integer in a certain mode */
5151
static inline double php_round_helper(double adjusted_value, double value, double coefficient, int mode) {
52-
double integral, fractional, edge_case;
52+
double integral = adjusted_value >= 0.0 ? floor(adjusted_value) : ceil(adjusted_value);
5353
double value_abs = fabs(value);
54+
double edge_case;
5455

55-
/* Split the input value into the integral and fractional part.
56-
*
57-
* Both parts will have the same sign as the input value. We take
58-
* the absolute value of the fractional part (which will not result
59-
* in branches in the assembly) to make the following cases simpler.
60-
*/
61-
fractional = fabs(modf(adjusted_value, &integral));
6256
if (fabs(adjusted_value) >= value_abs) {
6357
edge_case = fabs((integral + copysign(0.5, integral)) / coefficient);
6458
} else {

0 commit comments

Comments
 (0)