Skip to content

Commit b8a9d86

Browse files
committed
Fix sqrt of -INF returning -INF instead of NAN
1 parent e0b09a3 commit b8a9d86

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/math.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ void php_decimal_sqrt(mpd_t *res, const mpd_t *op1, zend_long prec)
220220
{
221221
uint32_t status = 0;
222222

223-
if (UNEXPECTED(mpd_isspecial(op1))) {
224-
mpd_qcopy(res, op1, &status);
223+
if (mpd_isnegative(op1)) {
224+
php_decimal_set_nan(res);
225225
return;
226226
}
227227

228-
if (mpd_isnegative(op1)) {
229-
php_decimal_set_nan(res);
228+
if (UNEXPECTED(mpd_isspecial(op1))) {
229+
mpd_qcopy(res, op1, &status);
230230
return;
231231
}
232232

tests/Decimal/methods/sqrt.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $tests = [
2828

2929
[Decimal::valueOf( "NAN"), "NAN", Decimal::DEFAULT_PRECISION],
3030
[Decimal::valueOf( "INF"), "INF", Decimal::DEFAULT_PRECISION],
31-
[Decimal::valueOf("-INF"), "-INF", Decimal::DEFAULT_PRECISION],
31+
[Decimal::valueOf("-INF"), "NAN", Decimal::DEFAULT_PRECISION],
3232
];
3333

3434
foreach ($tests as $test) {

0 commit comments

Comments
 (0)