summaryrefslogtreecommitdiff
path: root/ext/standard/math.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/math.c')
-rw-r--r--ext/standard/math.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/ext/standard/math.c b/ext/standard/math.c
index 8333fe7c5..b656fafae 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -13,13 +13,13 @@
| 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> |
+----------------------------------------------------------------------+
*/
-/* $Id: math.c 306939 2011-01-01 02:19:59Z felipe $ */
+/* $Id: math.c 312074 2011-06-12 00:56:18Z cataphract $ */
#include "php.h"
#include "php_math.h"
@@ -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));