From cd36614db2b88bb96afda121ff4b5587e15b4b7e Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Mon, 21 Feb 2022 18:11:54 +0100 Subject: [PATCH 1/2] Add tests for `isPositive()` and `isNegative()` --- tests/php7/methods/isNegative.phpt | 55 ++++++++++++++++++++++++++++++ tests/php7/methods/isPositive.phpt | 55 ++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 tests/php7/methods/isNegative.phpt create mode 100644 tests/php7/methods/isPositive.phpt diff --git a/tests/php7/methods/isNegative.phpt b/tests/php7/methods/isNegative.phpt new file mode 100644 index 0000000..b181342 --- /dev/null +++ b/tests/php7/methods/isNegative.phpt @@ -0,0 +1,55 @@ +--TEST-- +Decimal::isNegative +--SKIPIF-- + +--FILE-- +isNegative(); + + if ((string) $result !== (string) $expect) { + print_r(compact("number", "result", "expect")); + } +} +?> +--EXPECT-- diff --git a/tests/php7/methods/isPositive.phpt b/tests/php7/methods/isPositive.phpt new file mode 100644 index 0000000..593e42b --- /dev/null +++ b/tests/php7/methods/isPositive.phpt @@ -0,0 +1,55 @@ +--TEST-- +Decimal::isPositive +--SKIPIF-- + +--FILE-- +isPositive(); + + if ((string) $result !== (string) $expect) { + print_r(compact("number", "result", "expect")); + } +} +?> +--EXPECT-- From 531351863179362cdc2923acf535cd999dd0c2e7 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Mon, 21 Feb 2022 18:13:21 +0100 Subject: [PATCH 2/2] Fix `isPositive()` with `NaN` --- php_decimal.c | 10 ++++++++-- tests/php7/methods/isPositive.phpt | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/php_decimal.c b/php_decimal.c index 4871780..cbcb9c3 100644 --- a/php_decimal.c +++ b/php_decimal.c @@ -2373,7 +2373,10 @@ PHP_DECIMAL_ARGINFO_END() PHP_DECIMAL_METHOD(isPositive) { PHP_DECIMAL_PARAMS_PARSE_NONE(); - RETURN_BOOL(mpd_ispositive(THIS_MPD())); + + mpd_t *mpd = THIS_MPD(); + + RETURN_BOOL(!mpd_isnan(mpd) && mpd_ispositive(mpd)); } /** @@ -2384,7 +2387,10 @@ PHP_DECIMAL_ARGINFO_END() PHP_DECIMAL_METHOD(isNegative) { PHP_DECIMAL_PARAMS_PARSE_NONE(); - RETURN_BOOL(mpd_isnegative(THIS_MPD())); + + mpd_t *mpd = THIS_MPD(); + + RETURN_BOOL(!mpd_isnan(mpd) && mpd_isnegative(mpd)); } /** diff --git a/tests/php7/methods/isPositive.phpt b/tests/php7/methods/isPositive.phpt index 593e42b..96e0fc2 100644 --- a/tests/php7/methods/isPositive.phpt +++ b/tests/php7/methods/isPositive.phpt @@ -37,7 +37,7 @@ $tests = [ ["-2.5", false], ["-3.5", false], - [ "NAN", true], + [ "NAN", false], [ "INF", true], ["-INF", false], ];