POWER Needs to Accept NULL Args

Investigating issue #1622, I found that its extremely complicated formula, which had been leading to an incorrect result, now led to an exception. I am able to fix the exception; unfortunately, I am no closer to resolving the original issue. So I'll apply the baby step while continuing to investigate. Function POWER had changed from untyped args to a defined set of types. The set of types was determined according to the doc block, but that was incomplete - it had neglected to include `null` and `bool`. This PR corrects the function prototype and the doc block, and adds the missing tests for those conditions.
This commit is contained in:
oleibman
2024-05-16 00:25:47 -07:00
parent 563de5f3da
commit f8d994b6e7
2 changed files with 8 additions and 3 deletions
@@ -52,14 +52,14 @@ class Operations
*
* Computes x raised to the power y.
*
* @param array|float|int|string $x Or can be an array of values
* @param array|float|int|string $y Or can be an array of values
* @param null|array|bool|float|int|string $x Or can be an array of values
* @param null|array|bool|float|int|string $y Or can be an array of values
*
* @return array|float|int|string The result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function power(array|float|int|string $x, array|float|int|string $y): array|float|int|string
public static function power(null|array|bool|float|int|string $x, null|array|bool|float|int|string $y): array|float|int|string
{
if (is_array($x) || is_array($y)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $y);
@@ -410,4 +410,9 @@ return [
],
['#VALUE!', 'x', 2],
['#VALUE!', 2, 'x'],
'exponent is null' => [1, 2, null],
'base is null' => [0, null, 2],
'both null' => ['#NUM!', null, null],
'exponent is bool' => [2, 2, true],
'base is bool' => [0, false, 2],
];