-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed GH-16236: Fixed a bug in BcMath\Number::pow()
and bcpow()
when raising negative powers of 0
.
#16694
Fixed GH-16236: Fixed a bug in BcMath\Number::pow()
and bcpow()
when raising negative powers of 0
.
#16694
Changes from 1 commit
c048993
62878da
4cfc788
2e44b1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a stub of this to https://wiki.php.net/rfc/deprecations_php_8_5 so it is not forgotten, or follow-up PR to make this emit an E_WARNING or Throwing on master. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Var_dup the result of this to see what the output is? |
||
|
||
echo 'done!'; | ||
?> | ||
--EXPECT-- | ||
done! |
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 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to continue using
base