summaryrefslogtreecommitdiff
path: root/ext/standard/math.c
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2014-02-06 09:38:50 +0100
committerBob Weinand <bobwei9@hotmail.com>2014-02-06 09:38:50 +0100
commit45d2df5f119d17804ccf6068cbe1132e118579b2 (patch)
treee3014245763e4290de480fad0b1142728314b965 /ext/standard/math.c
parentb33060af82c648bb3971de9d8fe67e52781cbd7a (diff)
parente5ded6e843fc43dde4b6c65405a1d3e2ae026eb4 (diff)
downloadphp-git-45d2df5f119d17804ccf6068cbe1132e118579b2.tar.gz
Merge branch 'datibbaw/pow-operator' into PHP-5.6broken-5.6-20140206
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 2be049f200..65702ddf14 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);
}
/* }}} */