]> granicus.if.org Git - php/commitdiff
- Reverted r301991, which is a (partial) fix to bug #52550, addressing an
authorGustavo André dos Santos Lopes <cataphract@php.net>
Sun, 12 Jun 2011 00:56:18 +0000 (00:56 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Sun, 12 Jun 2011 00:56:18 +0000 (00:56 +0000)
  overflow in a signed subtraction. This fixes the overflow without
  changing the algorithm.

ext/standard/math.c

index aabd94b66ca2806af6939df699313d9bec87099e..6c679696c46cca267413f37f8c2171362a0a90e7 100644 (file)
@@ -13,7 +13,7 @@
    | license@php.net so we can mail you a copy immediately.               |
    +----------------------------------------------------------------------+
    | Authors: Jim Winstead <jimw@php.net>                                 |
-   |          Stig Sæther Bakken <ssb@php.net>                            |
+   |          Stig Sæther Bakken <ssb@php.net>                            |
    |          Zeev Suraski <zeev@zend.com>                                |
    | PHP 4.0 patches by Thies C. Arntzen <thies@thieso.net>               |
    +----------------------------------------------------------------------+
@@ -92,6 +92,18 @@ static inline double php_intpow10(int power) {
 }
 /* }}} */
 
+/* {{{ php_math_is_finite */
+static inline int php_math_is_finite(double value) {
+#if defined(PHP_WIN32)
+       return _finite(value);
+#elif defined(isfinite)
+       return isfinite(value);
+#else
+       return value == value && (value == 0. || value * 2. != value);
+#endif
+}
+/* }}} */
+
 /* {{{ php_round_helper
        Actually performs the rounding of a value to integer in a certain mode */
 static inline double php_round_helper(double value, int mode) {
@@ -129,11 +141,11 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
        double tmp_value;
        int precision_places;
 
-       if ((precision_places = php_intlog10abs(value)) > 0) {
-               precision_places = 14 - php_intlog10abs(value);
-       } else {
-               precision_places = 14;
+       if (!php_math_is_finite(value)) {
+               return value;
        }
+       
+       precision_places = 14 - php_intlog10abs(value);
 
        f1 = php_intpow10(abs(places));