-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PHP-8.4: Fixed a bug in BcMath\Number::pow() and bcpow() when raising negative powers of 0. (#16694)
- Loading branch information
Showing
8 changed files
with
147 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
bcpow() negative power of zero | ||
--EXTENSIONS-- | ||
bcmath | ||
--INI-- | ||
bcmath.scale=0 | ||
--FILE-- | ||
<?php | ||
$exponents = ["-15", "-1", "-9"]; | ||
$baseNumbers = ['0', '-0']; | ||
|
||
foreach ($baseNumbers as $baseNumber) { | ||
foreach ($exponents as $exponent) { | ||
try { | ||
echo bcpow($baseNumber, $exponent), "\n"; | ||
} catch (Error $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Negative power of zero | ||
Negative power of zero | ||
Negative power of zero | ||
Negative power of zero | ||
Negative power of zero | ||
Negative power of zero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--TEST-- | ||
BcMath\Number pow(): negative power of zero | ||
--EXTENSIONS-- | ||
bcmath | ||
--FILE-- | ||
<?php | ||
|
||
$values = [0, '0']; | ||
|
||
$exponents = [ | ||
[-3, 'int'], | ||
['-2', 'string'], | ||
[new BcMath\Number('-2'), 'object'], | ||
]; | ||
|
||
foreach ($values as $value) { | ||
$num = new BcMath\Number($value); | ||
|
||
foreach ($exponents as [$exponent, $type]) { | ||
echo "{$value} ** {$exponent}: {$type}\n"; | ||
try { | ||
$num->pow($exponent); | ||
} catch (Error $e) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
} | ||
} | ||
?> | ||
--EXPECT-- | ||
0 ** -3: int | ||
Negative power of zero | ||
0 ** -2: string | ||
Negative power of zero | ||
0 ** -2: object | ||
Negative power of zero | ||
0 ** -3: int | ||
Negative power of zero | ||
0 ** -2: string | ||
Negative power of zero | ||
0 ** -2: object | ||
Negative power of zero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--TEST-- | ||
BcMath\Number pow: negative power of zero by operator | ||
--EXTENSIONS-- | ||
bcmath | ||
--FILE-- | ||
<?php | ||
|
||
$values = [0, '0']; | ||
|
||
$exponents = [ | ||
[-3, 'int'], | ||
['-2', 'string'], | ||
[new BcMath\Number('-2'), 'object'], | ||
]; | ||
|
||
foreach ($values as $value) { | ||
$num = new BcMath\Number($value); | ||
|
||
foreach ($exponents as [$exponent, $type]) { | ||
echo "{$value} ** {$exponent}: {$type}\n"; | ||
try { | ||
$num ** $exponent; | ||
} catch (Error $e) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
} | ||
} | ||
?> | ||
--EXPECT-- | ||
0 ** -3: int | ||
Negative power of zero | ||
0 ** -2: string | ||
Negative power of zero | ||
0 ** -2: object | ||
Negative power of zero | ||
0 ** -3: int | ||
Negative power of zero | ||
0 ** -2: string | ||
Negative power of zero | ||
0 ** -2: object | ||
Negative power of zero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters