Skip to content

Commit 5313518

Browse files
committed
Fix isPositive() with NaN
1 parent cd36614 commit 5313518

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

php_decimal.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,10 @@ PHP_DECIMAL_ARGINFO_END()
23732373
PHP_DECIMAL_METHOD(isPositive)
23742374
{
23752375
PHP_DECIMAL_PARAMS_PARSE_NONE();
2376-
RETURN_BOOL(mpd_ispositive(THIS_MPD()));
2376+
2377+
mpd_t *mpd = THIS_MPD();
2378+
2379+
RETURN_BOOL(!mpd_isnan(mpd) && mpd_ispositive(mpd));
23772380
}
23782381

23792382
/**
@@ -2384,7 +2387,10 @@ PHP_DECIMAL_ARGINFO_END()
23842387
PHP_DECIMAL_METHOD(isNegative)
23852388
{
23862389
PHP_DECIMAL_PARAMS_PARSE_NONE();
2387-
RETURN_BOOL(mpd_isnegative(THIS_MPD()));
2390+
2391+
mpd_t *mpd = THIS_MPD();
2392+
2393+
RETURN_BOOL(!mpd_isnan(mpd) && mpd_isnegative(mpd));
23882394
}
23892395

23902396
/**

tests/php7/methods/isPositive.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $tests = [
3737
["-2.5", false],
3838
["-3.5", false],
3939

40-
[ "NAN", true],
40+
[ "NAN", false],
4141
[ "INF", true],
4242
["-INF", false],
4343
];

0 commit comments

Comments
 (0)