Skip to content

Commit c085eee

Browse files
committed
Removed unnecessary formatting changes
1 parent 76ab816 commit c085eee

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

ext/standard/math.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static inline int php_intlog10abs(double value) {
3636
value = fabs(value);
3737

3838
if (value < 1e-8 || value > 1e22) {
39-
return (int) floor(log10(value));
39+
return (int)floor(log10(value));
4040
} else {
4141
/* Do a binary search with 5 steps */
4242
int result = 15;
@@ -79,7 +79,7 @@ static inline int php_intlog10abs(double value) {
7979
static inline double php_intpow10(int power) {
8080
/* Not in lookup table */
8181
if (power < 0 || power > 22) {
82-
return pow(10.0, (double) power);
82+
return pow(10.0, (double)power);
8383
}
8484

8585
static const double powers[] = {
@@ -197,7 +197,7 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
197197
return value;
198198
}
199199

200-
places = places < INT_MIN + 1 ? INT_MIN + 1 : places;
200+
places = places < INT_MIN+1 ? INT_MIN+1 : places;
201201
precision_places = 14 - php_intlog10abs(value);
202202

203203
f1 = php_intpow10(abs(places));
@@ -206,9 +206,9 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
206206
the requested places BUT is small enough to make sure a non-zero value
207207
is returned, pre-round the result to the precision */
208208
if (precision_places > places && precision_places - 15 < places) {
209-
int64_t use_precision = precision_places < INT_MIN + 1 ? INT_MIN + 1 : precision_places;
209+
int64_t use_precision = precision_places < INT_MIN+1 ? INT_MIN+1 : precision_places;
210210

211-
f2 = php_intpow10(abs((int) use_precision));
211+
f2 = php_intpow10(abs((int)use_precision));
212212
if (use_precision >= 0) {
213213
tmp_value = value * f2;
214214
} else {
@@ -219,9 +219,9 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
219219
tmp_value = php_round_helper(tmp_value, mode);
220220

221221
use_precision = places - precision_places;
222-
use_precision = use_precision < INT_MIN + 1 ? INT_MIN + 1 : use_precision;
222+
use_precision = use_precision < INT_MIN+1 ? INT_MIN+1 : use_precision;
223223
/* now correctly move the decimal point */
224-
f2 = php_intpow10(abs((int) use_precision));
224+
f2 = php_intpow10(abs((int)use_precision));
225225
/* because places < precision_places */
226226
tmp_value = tmp_value / f2;
227227
} else {
@@ -1353,6 +1353,16 @@ PHP_FUNCTION(number_format)
13531353
break;
13541354

13551355
case IS_DOUBLE:
1356+
// double values of >= 2^52 can not have fractional digits anymore
1357+
// Casting to long on 64bit will not loose precision on rounding
1358+
if (UNEXPECTED(
1359+
(Z_DVAL_P(num) >= 4503599627370496.0 || Z_DVAL_P(num) <= -4503599627370496.0)
1360+
&& ZEND_DOUBLE_FITS_LONG(Z_DVAL_P(num))
1361+
)) {
1362+
RETURN_STR(_php_math_number_format_long((zend_long)Z_DVAL_P(num), dec, dec_point, dec_point_len, thousand_sep, thousand_sep_len));
1363+
break;
1364+
}
1365+
13561366
if (dec >= 0) {
13571367
dec_int = ZEND_LONG_INT_OVFL(dec) ? INT_MAX : (int)dec;
13581368
} else {

0 commit comments

Comments
 (0)