File tree Expand file tree Collapse file tree 3 files changed +118
-2
lines changed Expand file tree Collapse file tree 3 files changed +118
-2
lines changed Original file line number Diff line number Diff line change @@ -2373,7 +2373,10 @@ PHP_DECIMAL_ARGINFO_END()
23732373PHP_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()
23842387PHP_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/**
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Decimal::isNegative
3+ --SKIPIF--
4+ <?php
5+ if (!extension_loaded ("decimal " )) echo "skip " ;
6+ ?>
7+ --FILE--
8+ <?php
9+ use Decimal \Decimal ;
10+
11+ /**
12+ * Shortcut to construct a new decimal.
13+ */
14+ function decimal (...$ args ) { return new Decimal (...$ args ); }
15+
16+ $ tests = [
17+ /* Number, expected */
18+
19+ [ "1E-50 " , false ],
20+ ["-1E-50 " , true ],
21+
22+ ["0 " , false ],
23+ ["-0 " , true ],
24+ [1 , false ],
25+ [2 , false ],
26+ [3 , false ],
27+
28+ [-1 , true ],
29+ [-2 , true ],
30+ [-3 , true ],
31+
32+ ["1.5 " , false ],
33+ ["2.5 " , false ],
34+ ["3.5 " , false ],
35+
36+ ["-1.5 " , true ],
37+ ["-2.5 " , true ],
38+ ["-3.5 " , true ],
39+
40+ [ "NAN " , false ],
41+ [ "INF " , false ],
42+ ["-INF " , true ],
43+ ];
44+
45+ foreach ($ tests as $ pair ) {
46+ $ number = $ pair [0 ];
47+ $ expect = $ pair [1 ];
48+ $ result = decimal ($ number )->isNegative ();
49+
50+ if ((string ) $ result !== (string ) $ expect ) {
51+ print_r (compact ("number " , "result " , "expect " ));
52+ }
53+ }
54+ ?>
55+ --EXPECT--
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Decimal::isPositive
3+ --SKIPIF--
4+ <?php
5+ if (!extension_loaded ("decimal " )) echo "skip " ;
6+ ?>
7+ --FILE--
8+ <?php
9+ use Decimal \Decimal ;
10+
11+ /**
12+ * Shortcut to construct a new decimal.
13+ */
14+ function decimal (...$ args ) { return new Decimal (...$ args ); }
15+
16+ $ tests = [
17+ /* Number, expected */
18+
19+ [ "1E-50 " , true ],
20+ ["-1E-50 " , false ],
21+
22+ ["0 " , true ],
23+ ["-0 " , false ],
24+ [1 , true ],
25+ [2 , true ],
26+ [3 , true ],
27+
28+ [-1 , false ],
29+ [-2 , false ],
30+ [-3 , false ],
31+
32+ ["1.5 " , true ],
33+ ["2.5 " , true ],
34+ ["3.5 " , true ],
35+
36+ ["-1.5 " , false ],
37+ ["-2.5 " , false ],
38+ ["-3.5 " , false ],
39+
40+ [ "NAN " , false ],
41+ [ "INF " , true ],
42+ ["-INF " , false ],
43+ ];
44+
45+ foreach ($ tests as $ pair ) {
46+ $ number = $ pair [0 ];
47+ $ expect = $ pair [1 ];
48+ $ result = decimal ($ number )->isPositive ();
49+
50+ if ((string ) $ result !== (string ) $ expect ) {
51+ print_r (compact ("number " , "result " , "expect " ));
52+ }
53+ }
54+ ?>
55+ --EXPECT--
You can’t perform that action at this time.
0 commit comments