mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Added deprecation Division by zero when using power with zero as base and negative exponent
RFC: https://wiki.php.net/rfc/raising_zero_to_power_of_negative_number Closes GH-13128
This commit is contained in:
parent
92b9543ca9
commit
23afe57f01
14 changed files with 564 additions and 15 deletions
|
@ -352,6 +352,7 @@ PHP 8.4 UPGRADE NOTES
|
||||||
- Standard:
|
- Standard:
|
||||||
. Calling stream_context_set_option() with 2 arguments is deprecated.
|
. Calling stream_context_set_option() with 2 arguments is deprecated.
|
||||||
Use stream_context_set_options() instead.
|
Use stream_context_set_options() instead.
|
||||||
|
. Raising zero to the power of negative number is deprecated.
|
||||||
|
|
||||||
========================================
|
========================================
|
||||||
5. Changed Functions
|
5. Changed Functions
|
||||||
|
@ -545,6 +546,7 @@ PHP 8.4 UPGRADE NOTES
|
||||||
. Added the http_get_last_response_headers() and
|
. Added the http_get_last_response_headers() and
|
||||||
http_clear_last_response_headers() that allows retrieving the same content
|
http_clear_last_response_headers() that allows retrieving the same content
|
||||||
as the magic $http_response_header variable.
|
as the magic $http_response_header variable.
|
||||||
|
. Added function fpow() following rules of IEEE 754.
|
||||||
|
|
||||||
- XSL:
|
- XSL:
|
||||||
. Added XSLTProcessor::registerPhpFunctionNS().
|
. Added XSLTProcessor::registerPhpFunctionNS().
|
||||||
|
|
|
@ -8,6 +8,7 @@ if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
|
||||||
?>
|
?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
|
error_reporting(E_ALL ^ E_DEPRECATED);
|
||||||
|
|
||||||
$binaryOperators = [
|
$binaryOperators = [
|
||||||
"==",
|
"==",
|
||||||
|
@ -122,7 +123,7 @@ function prepareBinaryLine($op1, $op2, $cmp, $operator) {
|
||||||
try {
|
try {
|
||||||
$result = makeParam($cmp());
|
$result = makeParam($cmp());
|
||||||
$line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error }";
|
$line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error }";
|
||||||
} catch (Error $e) {
|
} catch (Throwable $e) {
|
||||||
$msg = makeParam($e->getMessage());
|
$msg = makeParam($e->getMessage());
|
||||||
$line .= "try { $compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
|
$line .= "try { $compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
|
||||||
}
|
}
|
||||||
|
@ -138,7 +139,7 @@ function prepareUnaryLine($op, $cmp, $operator) {
|
||||||
try {
|
try {
|
||||||
$result = makeParam($cmp());
|
$result = makeParam($cmp());
|
||||||
$line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error }";
|
$line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error }";
|
||||||
} catch (Error $e) {
|
} catch (Throwable $e) {
|
||||||
$msg = makeParam($e->getMessage());
|
$msg = makeParam($e->getMessage());
|
||||||
$line .= "try { $compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
|
$line .= "try { $compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
|
||||||
}
|
}
|
||||||
|
|
|
@ -8992,6 +8992,10 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co
|
||||||
/* Division by zero throws an error. */
|
/* Division by zero throws an error. */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if ((opcode == ZEND_POW) && zval_get_long(op1) == 0 && zval_get_double(op2) < 0) {
|
||||||
|
/* 0 ** (<0) throws a division by zero error. */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
if ((opcode == ZEND_SL || opcode == ZEND_SR) && zval_get_long(op2) < 0) {
|
if ((opcode == ZEND_SL || opcode == ZEND_SR) && zval_get_long(op2) < 0) {
|
||||||
/* Shift by negative number throws an error. */
|
/* Shift by negative number throws an error. */
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -1287,6 +1287,20 @@ ZEND_API zend_result ZEND_FASTCALL mul_function(zval *result, zval *op1, zval *o
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
static void ZEND_COLD zend_power_base_0_exponent_lt_0_error(void)
|
||||||
|
{
|
||||||
|
zend_error(E_DEPRECATED, "Power of base 0 and negative exponent is deprecated");
|
||||||
|
}
|
||||||
|
|
||||||
|
static double safe_pow(double base, double exponent)
|
||||||
|
{
|
||||||
|
if (UNEXPECTED(base == 0.0 && exponent < 0.0)) {
|
||||||
|
zend_power_base_0_exponent_lt_0_error();
|
||||||
|
}
|
||||||
|
|
||||||
|
return pow(base, exponent);
|
||||||
|
}
|
||||||
|
|
||||||
static zend_result ZEND_FASTCALL pow_function_base(zval *result, zval *op1, zval *op2) /* {{{ */
|
static zend_result ZEND_FASTCALL pow_function_base(zval *result, zval *op1, zval *op2) /* {{{ */
|
||||||
{
|
{
|
||||||
uint8_t type_pair = TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2));
|
uint8_t type_pair = TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2));
|
||||||
|
@ -1311,14 +1325,14 @@ static zend_result ZEND_FASTCALL pow_function_base(zval *result, zval *op1, zval
|
||||||
--i;
|
--i;
|
||||||
ZEND_SIGNED_MULTIPLY_LONG(l1, l2, l1, dval, overflow);
|
ZEND_SIGNED_MULTIPLY_LONG(l1, l2, l1, dval, overflow);
|
||||||
if (overflow) {
|
if (overflow) {
|
||||||
ZVAL_DOUBLE(result, dval * pow(l2, i));
|
ZVAL_DOUBLE(result, dval * safe_pow(l2, i));
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
i /= 2;
|
i /= 2;
|
||||||
ZEND_SIGNED_MULTIPLY_LONG(l2, l2, l2, dval, overflow);
|
ZEND_SIGNED_MULTIPLY_LONG(l2, l2, l2, dval, overflow);
|
||||||
if (overflow) {
|
if (overflow) {
|
||||||
ZVAL_DOUBLE(result, (double)l1 * pow(dval, i));
|
ZVAL_DOUBLE(result, (double)l1 * safe_pow(dval, i));
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1326,17 +1340,17 @@ static zend_result ZEND_FASTCALL pow_function_base(zval *result, zval *op1, zval
|
||||||
/* i == 0 */
|
/* i == 0 */
|
||||||
ZVAL_LONG(result, l1);
|
ZVAL_LONG(result, l1);
|
||||||
} else {
|
} else {
|
||||||
ZVAL_DOUBLE(result, pow((double)Z_LVAL_P(op1), (double)Z_LVAL_P(op2)));
|
ZVAL_DOUBLE(result, safe_pow((double)Z_LVAL_P(op1), (double)Z_LVAL_P(op2)));
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_DOUBLE))) {
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_DOUBLE))) {
|
||||||
ZVAL_DOUBLE(result, pow(Z_DVAL_P(op1), Z_DVAL_P(op2)));
|
ZVAL_DOUBLE(result, safe_pow(Z_DVAL_P(op1), Z_DVAL_P(op2)));
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_DOUBLE))) {
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_DOUBLE))) {
|
||||||
ZVAL_DOUBLE(result, pow((double)Z_LVAL_P(op1), Z_DVAL_P(op2)));
|
ZVAL_DOUBLE(result, safe_pow((double)Z_LVAL_P(op1), Z_DVAL_P(op2)));
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_LONG))) {
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_LONG))) {
|
||||||
ZVAL_DOUBLE(result, pow(Z_DVAL_P(op1), (double)Z_LVAL_P(op2)));
|
ZVAL_DOUBLE(result, safe_pow(Z_DVAL_P(op1), (double)Z_LVAL_P(op2)));
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
|
|
|
@ -3274,6 +3274,11 @@ function fmod(float $num1, float $num2): float {}
|
||||||
*/
|
*/
|
||||||
function fdiv(float $num1, float $num2): float {}
|
function fdiv(float $num1, float $num2): float {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @compile-time-eval
|
||||||
|
*/
|
||||||
|
function fpow(float $num1, float $num2): float {}
|
||||||
|
|
||||||
/* microtime.c */
|
/* microtime.c */
|
||||||
|
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
|
|
6
ext/standard/basic_functions_arginfo.h
generated
6
ext/standard/basic_functions_arginfo.h
generated
|
@ -1,5 +1,5 @@
|
||||||
/* This is a generated file, edit the .stub.php file instead.
|
/* This is a generated file, edit the .stub.php file instead.
|
||||||
* Stub hash: 1ef54fdebc6a206c4af3438130db0cd12a62c8b6 */
|
* Stub hash: 5d8e13990ce18bebc9c7e6a0a9a7ad8b7593d35b */
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
|
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
|
||||||
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
|
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
|
||||||
|
@ -1732,6 +1732,8 @@ ZEND_END_ARG_INFO()
|
||||||
|
|
||||||
#define arginfo_fdiv arginfo_fmod
|
#define arginfo_fdiv arginfo_fmod
|
||||||
|
|
||||||
|
#define arginfo_fpow arginfo_fmod
|
||||||
|
|
||||||
#if defined(HAVE_GETTIMEOFDAY)
|
#if defined(HAVE_GETTIMEOFDAY)
|
||||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_microtime, 0, 0, MAY_BE_STRING|MAY_BE_DOUBLE)
|
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_microtime, 0, 0, MAY_BE_STRING|MAY_BE_DOUBLE)
|
||||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, as_float, _IS_BOOL, 0, "false")
|
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, as_float, _IS_BOOL, 0, "false")
|
||||||
|
@ -2789,6 +2791,7 @@ ZEND_FUNCTION(base_convert);
|
||||||
ZEND_FUNCTION(number_format);
|
ZEND_FUNCTION(number_format);
|
||||||
ZEND_FUNCTION(fmod);
|
ZEND_FUNCTION(fmod);
|
||||||
ZEND_FUNCTION(fdiv);
|
ZEND_FUNCTION(fdiv);
|
||||||
|
ZEND_FUNCTION(fpow);
|
||||||
#if defined(HAVE_GETTIMEOFDAY)
|
#if defined(HAVE_GETTIMEOFDAY)
|
||||||
ZEND_FUNCTION(microtime);
|
ZEND_FUNCTION(microtime);
|
||||||
#endif
|
#endif
|
||||||
|
@ -3428,6 +3431,7 @@ static const zend_function_entry ext_functions[] = {
|
||||||
ZEND_RAW_FENTRY("number_format", zif_number_format, arginfo_number_format, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
|
ZEND_RAW_FENTRY("number_format", zif_number_format, arginfo_number_format, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
|
||||||
ZEND_RAW_FENTRY("fmod", zif_fmod, arginfo_fmod, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
|
ZEND_RAW_FENTRY("fmod", zif_fmod, arginfo_fmod, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
|
||||||
ZEND_RAW_FENTRY("fdiv", zif_fdiv, arginfo_fdiv, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
|
ZEND_RAW_FENTRY("fdiv", zif_fdiv, arginfo_fdiv, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
|
||||||
|
ZEND_RAW_FENTRY("fpow", zif_fpow, arginfo_fpow, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
|
||||||
#if defined(HAVE_GETTIMEOFDAY)
|
#if defined(HAVE_GETTIMEOFDAY)
|
||||||
ZEND_FE(microtime, arginfo_microtime)
|
ZEND_FE(microtime, arginfo_microtime)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1389,6 +1389,20 @@ PHP_FUNCTION(fdiv)
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ Perform floating-point exponentiation with IEEE-754 semantics. */
|
||||||
|
PHP_FUNCTION(fpow)
|
||||||
|
{
|
||||||
|
double base, exponent;
|
||||||
|
|
||||||
|
ZEND_PARSE_PARAMETERS_START(2, 2)
|
||||||
|
Z_PARAM_DOUBLE(base)
|
||||||
|
Z_PARAM_DOUBLE(exponent)
|
||||||
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
|
|
||||||
|
RETURN_DOUBLE(pow(base, exponent));
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ Returns the integer quotient of the division of dividend by divisor */
|
/* {{{ Returns the integer quotient of the division of dividend by divisor */
|
||||||
PHP_FUNCTION(intdiv)
|
PHP_FUNCTION(intdiv)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@ var_dump($inf==='abc');
|
||||||
var_dump($inf===$inf);
|
var_dump($inf===$inf);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
float(NAN)
|
float(NAN)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(false)
|
bool(false)
|
||||||
|
@ -57,6 +57,8 @@ bool(false)
|
||||||
bool(false)
|
bool(false)
|
||||||
bool(false)
|
bool(false)
|
||||||
bool(false)
|
bool(false)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
float(INF)
|
float(INF)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(false)
|
bool(false)
|
||||||
|
|
362
ext/standard/tests/math/fpow.phpt
Normal file
362
ext/standard/tests/math/fpow.phpt
Normal file
|
@ -0,0 +1,362 @@
|
||||||
|
--TEST--
|
||||||
|
fpow() function
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$numbers = [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
-1,
|
||||||
|
1.0,
|
||||||
|
-1.0,
|
||||||
|
2,
|
||||||
|
-2,
|
||||||
|
2.1,
|
||||||
|
-2.1,
|
||||||
|
0.1,
|
||||||
|
-0.1,
|
||||||
|
0.0,
|
||||||
|
-0.0,
|
||||||
|
10,
|
||||||
|
-10,
|
||||||
|
INF,
|
||||||
|
-INF,
|
||||||
|
NAN,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($numbers as $base) {
|
||||||
|
foreach ($numbers as $exp) {
|
||||||
|
print str_pad($base, 4, " ", STR_PAD_LEFT) .
|
||||||
|
" ** " .
|
||||||
|
str_pad($exp, 4) .
|
||||||
|
" = " .
|
||||||
|
fpow($base, $exp) .
|
||||||
|
PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
0 ** 0 = 1
|
||||||
|
0 ** 1 = 0
|
||||||
|
0 ** -1 = INF
|
||||||
|
0 ** 1 = 0
|
||||||
|
0 ** -1 = INF
|
||||||
|
0 ** 2 = 0
|
||||||
|
0 ** -2 = INF
|
||||||
|
0 ** 2.1 = 0
|
||||||
|
0 ** -2.1 = INF
|
||||||
|
0 ** 0.1 = 0
|
||||||
|
0 ** -0.1 = INF
|
||||||
|
0 ** 0 = 1
|
||||||
|
0 ** -0 = 1
|
||||||
|
0 ** 10 = 0
|
||||||
|
0 ** -10 = INF
|
||||||
|
0 ** INF = 0
|
||||||
|
0 ** -INF = INF
|
||||||
|
0 ** NAN = NAN
|
||||||
|
1 ** 0 = 1
|
||||||
|
1 ** 1 = 1
|
||||||
|
1 ** -1 = 1
|
||||||
|
1 ** 1 = 1
|
||||||
|
1 ** -1 = 1
|
||||||
|
1 ** 2 = 1
|
||||||
|
1 ** -2 = 1
|
||||||
|
1 ** 2.1 = 1
|
||||||
|
1 ** -2.1 = 1
|
||||||
|
1 ** 0.1 = 1
|
||||||
|
1 ** -0.1 = 1
|
||||||
|
1 ** 0 = 1
|
||||||
|
1 ** -0 = 1
|
||||||
|
1 ** 10 = 1
|
||||||
|
1 ** -10 = 1
|
||||||
|
1 ** INF = 1
|
||||||
|
1 ** -INF = 1
|
||||||
|
1 ** NAN = 1
|
||||||
|
-1 ** 0 = 1
|
||||||
|
-1 ** 1 = -1
|
||||||
|
-1 ** -1 = -1
|
||||||
|
-1 ** 1 = -1
|
||||||
|
-1 ** -1 = -1
|
||||||
|
-1 ** 2 = 1
|
||||||
|
-1 ** -2 = 1
|
||||||
|
-1 ** 2.1 = NAN
|
||||||
|
-1 ** -2.1 = NAN
|
||||||
|
-1 ** 0.1 = NAN
|
||||||
|
-1 ** -0.1 = NAN
|
||||||
|
-1 ** 0 = 1
|
||||||
|
-1 ** -0 = 1
|
||||||
|
-1 ** 10 = 1
|
||||||
|
-1 ** -10 = 1
|
||||||
|
-1 ** INF = 1
|
||||||
|
-1 ** -INF = 1
|
||||||
|
-1 ** NAN = NAN
|
||||||
|
1 ** 0 = 1
|
||||||
|
1 ** 1 = 1
|
||||||
|
1 ** -1 = 1
|
||||||
|
1 ** 1 = 1
|
||||||
|
1 ** -1 = 1
|
||||||
|
1 ** 2 = 1
|
||||||
|
1 ** -2 = 1
|
||||||
|
1 ** 2.1 = 1
|
||||||
|
1 ** -2.1 = 1
|
||||||
|
1 ** 0.1 = 1
|
||||||
|
1 ** -0.1 = 1
|
||||||
|
1 ** 0 = 1
|
||||||
|
1 ** -0 = 1
|
||||||
|
1 ** 10 = 1
|
||||||
|
1 ** -10 = 1
|
||||||
|
1 ** INF = 1
|
||||||
|
1 ** -INF = 1
|
||||||
|
1 ** NAN = 1
|
||||||
|
-1 ** 0 = 1
|
||||||
|
-1 ** 1 = -1
|
||||||
|
-1 ** -1 = -1
|
||||||
|
-1 ** 1 = -1
|
||||||
|
-1 ** -1 = -1
|
||||||
|
-1 ** 2 = 1
|
||||||
|
-1 ** -2 = 1
|
||||||
|
-1 ** 2.1 = NAN
|
||||||
|
-1 ** -2.1 = NAN
|
||||||
|
-1 ** 0.1 = NAN
|
||||||
|
-1 ** -0.1 = NAN
|
||||||
|
-1 ** 0 = 1
|
||||||
|
-1 ** -0 = 1
|
||||||
|
-1 ** 10 = 1
|
||||||
|
-1 ** -10 = 1
|
||||||
|
-1 ** INF = 1
|
||||||
|
-1 ** -INF = 1
|
||||||
|
-1 ** NAN = NAN
|
||||||
|
2 ** 0 = 1
|
||||||
|
2 ** 1 = 2
|
||||||
|
2 ** -1 = 0.5
|
||||||
|
2 ** 1 = 2
|
||||||
|
2 ** -1 = 0.5
|
||||||
|
2 ** 2 = 4
|
||||||
|
2 ** -2 = 0.25
|
||||||
|
2 ** 2.1 = 4.2870938501452
|
||||||
|
2 ** -2.1 = 0.2332582478842
|
||||||
|
2 ** 0.1 = 1.0717734625363
|
||||||
|
2 ** -0.1 = 0.93303299153681
|
||||||
|
2 ** 0 = 1
|
||||||
|
2 ** -0 = 1
|
||||||
|
2 ** 10 = 1024
|
||||||
|
2 ** -10 = 0.0009765625
|
||||||
|
2 ** INF = INF
|
||||||
|
2 ** -INF = 0
|
||||||
|
2 ** NAN = NAN
|
||||||
|
-2 ** 0 = 1
|
||||||
|
-2 ** 1 = -2
|
||||||
|
-2 ** -1 = -0.5
|
||||||
|
-2 ** 1 = -2
|
||||||
|
-2 ** -1 = -0.5
|
||||||
|
-2 ** 2 = 4
|
||||||
|
-2 ** -2 = 0.25
|
||||||
|
-2 ** 2.1 = NAN
|
||||||
|
-2 ** -2.1 = NAN
|
||||||
|
-2 ** 0.1 = NAN
|
||||||
|
-2 ** -0.1 = NAN
|
||||||
|
-2 ** 0 = 1
|
||||||
|
-2 ** -0 = 1
|
||||||
|
-2 ** 10 = 1024
|
||||||
|
-2 ** -10 = 0.0009765625
|
||||||
|
-2 ** INF = INF
|
||||||
|
-2 ** -INF = 0
|
||||||
|
-2 ** NAN = NAN
|
||||||
|
2.1 ** 0 = 1
|
||||||
|
2.1 ** 1 = 2.1
|
||||||
|
2.1 ** -1 = 0.47619047619048
|
||||||
|
2.1 ** 1 = 2.1
|
||||||
|
2.1 ** -1 = 0.47619047619048
|
||||||
|
2.1 ** 2 = 4.41
|
||||||
|
2.1 ** -2 = 0.22675736961451
|
||||||
|
2.1 ** 2.1 = 4.7496380917422
|
||||||
|
2.1 ** -2.1 = 0.21054235726688
|
||||||
|
2.1 ** 0.1 = 1.0770154403044
|
||||||
|
2.1 ** -0.1 = 0.92849179554696
|
||||||
|
2.1 ** 0 = 1
|
||||||
|
2.1 ** -0 = 1
|
||||||
|
2.1 ** 10 = 1667.9880978201
|
||||||
|
2.1 ** -10 = 0.0005995246616609
|
||||||
|
2.1 ** INF = INF
|
||||||
|
2.1 ** -INF = 0
|
||||||
|
2.1 ** NAN = NAN
|
||||||
|
-2.1 ** 0 = 1
|
||||||
|
-2.1 ** 1 = -2.1
|
||||||
|
-2.1 ** -1 = -0.47619047619048
|
||||||
|
-2.1 ** 1 = -2.1
|
||||||
|
-2.1 ** -1 = -0.47619047619048
|
||||||
|
-2.1 ** 2 = 4.41
|
||||||
|
-2.1 ** -2 = 0.22675736961451
|
||||||
|
-2.1 ** 2.1 = NAN
|
||||||
|
-2.1 ** -2.1 = NAN
|
||||||
|
-2.1 ** 0.1 = NAN
|
||||||
|
-2.1 ** -0.1 = NAN
|
||||||
|
-2.1 ** 0 = 1
|
||||||
|
-2.1 ** -0 = 1
|
||||||
|
-2.1 ** 10 = 1667.9880978201
|
||||||
|
-2.1 ** -10 = 0.0005995246616609
|
||||||
|
-2.1 ** INF = INF
|
||||||
|
-2.1 ** -INF = 0
|
||||||
|
-2.1 ** NAN = NAN
|
||||||
|
0.1 ** 0 = 1
|
||||||
|
0.1 ** 1 = 0.1
|
||||||
|
0.1 ** -1 = 10
|
||||||
|
0.1 ** 1 = 0.1
|
||||||
|
0.1 ** -1 = 10
|
||||||
|
0.1 ** 2 = 0.01
|
||||||
|
0.1 ** -2 = 100
|
||||||
|
0.1 ** 2.1 = 0.0079432823472428
|
||||||
|
0.1 ** -2.1 = 125.89254117942
|
||||||
|
0.1 ** 0.1 = 0.79432823472428
|
||||||
|
0.1 ** -0.1 = 1.2589254117942
|
||||||
|
0.1 ** 0 = 1
|
||||||
|
0.1 ** -0 = 1
|
||||||
|
0.1 ** 10 = 1.0E-10
|
||||||
|
0.1 ** -10 = 10000000000
|
||||||
|
0.1 ** INF = 0
|
||||||
|
0.1 ** -INF = INF
|
||||||
|
0.1 ** NAN = NAN
|
||||||
|
-0.1 ** 0 = 1
|
||||||
|
-0.1 ** 1 = -0.1
|
||||||
|
-0.1 ** -1 = -10
|
||||||
|
-0.1 ** 1 = -0.1
|
||||||
|
-0.1 ** -1 = -10
|
||||||
|
-0.1 ** 2 = 0.01
|
||||||
|
-0.1 ** -2 = 100
|
||||||
|
-0.1 ** 2.1 = NAN
|
||||||
|
-0.1 ** -2.1 = NAN
|
||||||
|
-0.1 ** 0.1 = NAN
|
||||||
|
-0.1 ** -0.1 = NAN
|
||||||
|
-0.1 ** 0 = 1
|
||||||
|
-0.1 ** -0 = 1
|
||||||
|
-0.1 ** 10 = 1.0E-10
|
||||||
|
-0.1 ** -10 = 10000000000
|
||||||
|
-0.1 ** INF = 0
|
||||||
|
-0.1 ** -INF = INF
|
||||||
|
-0.1 ** NAN = NAN
|
||||||
|
0 ** 0 = 1
|
||||||
|
0 ** 1 = 0
|
||||||
|
0 ** -1 = INF
|
||||||
|
0 ** 1 = 0
|
||||||
|
0 ** -1 = INF
|
||||||
|
0 ** 2 = 0
|
||||||
|
0 ** -2 = INF
|
||||||
|
0 ** 2.1 = 0
|
||||||
|
0 ** -2.1 = INF
|
||||||
|
0 ** 0.1 = 0
|
||||||
|
0 ** -0.1 = INF
|
||||||
|
0 ** 0 = 1
|
||||||
|
0 ** -0 = 1
|
||||||
|
0 ** 10 = 0
|
||||||
|
0 ** -10 = INF
|
||||||
|
0 ** INF = 0
|
||||||
|
0 ** -INF = INF
|
||||||
|
0 ** NAN = NAN
|
||||||
|
-0 ** 0 = 1
|
||||||
|
-0 ** 1 = -0
|
||||||
|
-0 ** -1 = -INF
|
||||||
|
-0 ** 1 = -0
|
||||||
|
-0 ** -1 = -INF
|
||||||
|
-0 ** 2 = 0
|
||||||
|
-0 ** -2 = INF
|
||||||
|
-0 ** 2.1 = 0
|
||||||
|
-0 ** -2.1 = INF
|
||||||
|
-0 ** 0.1 = 0
|
||||||
|
-0 ** -0.1 = INF
|
||||||
|
-0 ** 0 = 1
|
||||||
|
-0 ** -0 = 1
|
||||||
|
-0 ** 10 = 0
|
||||||
|
-0 ** -10 = INF
|
||||||
|
-0 ** INF = 0
|
||||||
|
-0 ** -INF = INF
|
||||||
|
-0 ** NAN = NAN
|
||||||
|
10 ** 0 = 1
|
||||||
|
10 ** 1 = 10
|
||||||
|
10 ** -1 = 0.1
|
||||||
|
10 ** 1 = 10
|
||||||
|
10 ** -1 = 0.1
|
||||||
|
10 ** 2 = 100
|
||||||
|
10 ** -2 = 0.01
|
||||||
|
10 ** 2.1 = 125.89254117942
|
||||||
|
10 ** -2.1 = 0.0079432823472428
|
||||||
|
10 ** 0.1 = 1.2589254117942
|
||||||
|
10 ** -0.1 = 0.79432823472428
|
||||||
|
10 ** 0 = 1
|
||||||
|
10 ** -0 = 1
|
||||||
|
10 ** 10 = 10000000000
|
||||||
|
10 ** -10 = 1.0E-10
|
||||||
|
10 ** INF = INF
|
||||||
|
10 ** -INF = 0
|
||||||
|
10 ** NAN = NAN
|
||||||
|
-10 ** 0 = 1
|
||||||
|
-10 ** 1 = -10
|
||||||
|
-10 ** -1 = -0.1
|
||||||
|
-10 ** 1 = -10
|
||||||
|
-10 ** -1 = -0.1
|
||||||
|
-10 ** 2 = 100
|
||||||
|
-10 ** -2 = 0.01
|
||||||
|
-10 ** 2.1 = NAN
|
||||||
|
-10 ** -2.1 = NAN
|
||||||
|
-10 ** 0.1 = NAN
|
||||||
|
-10 ** -0.1 = NAN
|
||||||
|
-10 ** 0 = 1
|
||||||
|
-10 ** -0 = 1
|
||||||
|
-10 ** 10 = 10000000000
|
||||||
|
-10 ** -10 = 1.0E-10
|
||||||
|
-10 ** INF = INF
|
||||||
|
-10 ** -INF = 0
|
||||||
|
-10 ** NAN = NAN
|
||||||
|
INF ** 0 = 1
|
||||||
|
INF ** 1 = INF
|
||||||
|
INF ** -1 = 0
|
||||||
|
INF ** 1 = INF
|
||||||
|
INF ** -1 = 0
|
||||||
|
INF ** 2 = INF
|
||||||
|
INF ** -2 = 0
|
||||||
|
INF ** 2.1 = INF
|
||||||
|
INF ** -2.1 = 0
|
||||||
|
INF ** 0.1 = INF
|
||||||
|
INF ** -0.1 = 0
|
||||||
|
INF ** 0 = 1
|
||||||
|
INF ** -0 = 1
|
||||||
|
INF ** 10 = INF
|
||||||
|
INF ** -10 = 0
|
||||||
|
INF ** INF = INF
|
||||||
|
INF ** -INF = 0
|
||||||
|
INF ** NAN = NAN
|
||||||
|
-INF ** 0 = 1
|
||||||
|
-INF ** 1 = -INF
|
||||||
|
-INF ** -1 = -0
|
||||||
|
-INF ** 1 = -INF
|
||||||
|
-INF ** -1 = -0
|
||||||
|
-INF ** 2 = INF
|
||||||
|
-INF ** -2 = 0
|
||||||
|
-INF ** 2.1 = INF
|
||||||
|
-INF ** -2.1 = 0
|
||||||
|
-INF ** 0.1 = INF
|
||||||
|
-INF ** -0.1 = 0
|
||||||
|
-INF ** 0 = 1
|
||||||
|
-INF ** -0 = 1
|
||||||
|
-INF ** 10 = INF
|
||||||
|
-INF ** -10 = 0
|
||||||
|
-INF ** INF = INF
|
||||||
|
-INF ** -INF = 0
|
||||||
|
-INF ** NAN = NAN
|
||||||
|
NAN ** 0 = 1
|
||||||
|
NAN ** 1 = NAN
|
||||||
|
NAN ** -1 = NAN
|
||||||
|
NAN ** 1 = NAN
|
||||||
|
NAN ** -1 = NAN
|
||||||
|
NAN ** 2 = NAN
|
||||||
|
NAN ** -2 = NAN
|
||||||
|
NAN ** 2.1 = NAN
|
||||||
|
NAN ** -2.1 = NAN
|
||||||
|
NAN ** 0.1 = NAN
|
||||||
|
NAN ** -0.1 = NAN
|
||||||
|
NAN ** 0 = 1
|
||||||
|
NAN ** -0 = 1
|
||||||
|
NAN ** 10 = NAN
|
||||||
|
NAN ** -10 = NAN
|
||||||
|
NAN ** INF = NAN
|
||||||
|
NAN ** -INF = NAN
|
||||||
|
NAN ** NAN = NAN
|
|
@ -21,7 +21,8 @@ for ($i = 0; $i < count($values); $i++) {
|
||||||
var_dump($res);
|
var_dump($res);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
|
@ -21,7 +21,8 @@ for ($i = 0; $i < count($values); $i++) {
|
||||||
var_dump($res);
|
var_dump($res);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(false)
|
bool(false)
|
||||||
bool(false)
|
bool(false)
|
||||||
bool(false)
|
bool(false)
|
||||||
|
|
|
@ -23,7 +23,8 @@ for ($i = 0; $i < count($values); $i++) {
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(false)
|
bool(false)
|
||||||
bool(false)
|
bool(false)
|
||||||
bool(false)
|
bool(false)
|
||||||
|
|
|
@ -143,7 +143,7 @@ var_dump(epsilon_equal( LONG_MAX*LONG_MAX , pow(LONG_MAX,2.0) ));
|
||||||
var_dump(epsilon_equal( LONG_MIN*LONG_MIN , pow(LONG_MIN,2.0) ));
|
var_dump(epsilon_equal( LONG_MIN*LONG_MIN , pow(LONG_MIN,2.0) ));
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
1,1,0,0
|
1,1,0,0
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
@ -155,7 +155,11 @@ bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
@ -180,7 +184,11 @@ bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
@ -212,7 +220,11 @@ bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
@ -237,7 +249,11 @@ bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
122
ext/standard/tests/math/pow_divisionbyzero.phpt
Normal file
122
ext/standard/tests/math/pow_divisionbyzero.phpt
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
--TEST--
|
||||||
|
pow() division by zero error
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
var_dump(pow(0, -0));
|
||||||
|
var_dump(pow(0.0, -0));
|
||||||
|
var_dump(pow(0, -0.0));
|
||||||
|
var_dump(pow(0.0, -0.0));
|
||||||
|
var_dump(pow(0, -0.01));
|
||||||
|
var_dump(pow(0.0, -0.01));
|
||||||
|
var_dump(pow(0, -1));
|
||||||
|
var_dump(pow(0.0, -1));
|
||||||
|
var_dump(pow(0, -1.1));
|
||||||
|
var_dump(pow(0.0, -1.1));
|
||||||
|
|
||||||
|
var_dump(0 ** -0);
|
||||||
|
var_dump(0.0 ** -0);
|
||||||
|
var_dump(0 ** -0.0);
|
||||||
|
var_dump(0.0 ** -0.0);
|
||||||
|
var_dump(0 ** -0.01);
|
||||||
|
var_dump(0.0 ** -0.01);
|
||||||
|
var_dump(0 ** -1);
|
||||||
|
var_dump(0.0 ** -1);
|
||||||
|
var_dump(0 ** -1.1);
|
||||||
|
var_dump(0.0 ** -1.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
test();
|
||||||
|
test();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
int(1)
|
||||||
|
float(1)
|
||||||
|
float(1)
|
||||||
|
float(1)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
int(1)
|
||||||
|
float(1)
|
||||||
|
float(1)
|
||||||
|
float(1)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
int(1)
|
||||||
|
float(1)
|
||||||
|
float(1)
|
||||||
|
float(1)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
int(1)
|
||||||
|
float(1)
|
||||||
|
float(1)
|
||||||
|
float(1)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
||||||
|
|
||||||
|
Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d
|
||||||
|
float(INF)
|
Loading…
Add table
Add a link
Reference in a new issue