-
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.
Fixed a bug in BcMath\Number::pow() when raising negative powers of 0.
- Loading branch information
1 parent
5c7c5d9
commit 8a04775
Showing
6 changed files
with
113 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--TEST-- | ||
GH-16236 Segmentation fault (access null pointer) in ext/bcmath/libbcmath/src/rmzero.c:50 | ||
--EXTENSIONS-- | ||
bcmath | ||
--FILE-- | ||
<?php | ||
/** | ||
* The existing bcpow() specification returns 0 for negative powers. | ||
* This is mathematically incorrect and will need to be changed to raise an error at some point. | ||
* This test is to ensure the existing specifications until the specifications are changed. | ||
*/ | ||
bcpow('0', '-2'); | ||
|
||
echo 'done!'; | ||
?> | ||
--EXPECT-- | ||
done! |
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 |