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.c38
1 files changed, 1 insertions, 37 deletions
diff --git a/ext/standard/math.c b/ext/standard/math.c
index 2be049f20..65702ddf1 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -604,43 +604,7 @@ PHP_FUNCTION(pow)
return;
}
- /* make sure we're dealing with numbers */
- convert_scalar_to_number(zbase TSRMLS_CC);
- convert_scalar_to_number(zexp TSRMLS_CC);
-
- /* if both base and exponent were longs, we'll try to get a long out */
- if (Z_TYPE_P(zbase) == IS_LONG && Z_TYPE_P(zexp) == IS_LONG && Z_LVAL_P(zexp) >= 0) {
- long l1 = 1, l2 = Z_LVAL_P(zbase), i = Z_LVAL_P(zexp);
-
- if (i == 0) {
- RETURN_LONG(1L);
- } else if (l2 == 0) {
- RETURN_LONG(0);
- }
-
- /* calculate pow(long,long) in O(log exp) operations, bail if overflow */
- while (i >= 1) {
- long overflow;
- double dval = 0.0;
-
- if (i % 2) {
- --i;
- ZEND_SIGNED_MULTIPLY_LONG(l1,l2,l1,dval,overflow);
- if (overflow) RETURN_DOUBLE(dval * pow(l2,i));
- } else {
- i /= 2;
- ZEND_SIGNED_MULTIPLY_LONG(l2,l2,l2,dval,overflow);
- if (overflow) RETURN_DOUBLE((double)l1 * pow(dval,i));
- }
- if (i == 0) {
- RETURN_LONG(l1);
- }
- }
- }
- convert_to_double(zbase);
- convert_to_double(zexp);
-
- RETURN_DOUBLE(pow(Z_DVAL_P(zbase), Z_DVAL_P(zexp)));
+ pow_function(return_value, zbase, zexp TSRMLS_CC);
}
/* }}} */