Skip to content

Commit 6cd47ba

Browse files
committed
Add Base.ispositive, Base.isnegative
1 parent 54116f0 commit 6cd47ba

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/decimal.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Base.iszero(x::Decimal) = iszero(x.c)
1919
Base.isfinite(x::Decimal) = true
2020
Base.isnan(x::Decimal) = false
2121

22+
if VERSION v"1.13"
23+
Base.ispositive(x::Decimal) = !x.s && !iszero(x.c)
24+
Base.isnegative(x::Decimal) = x.s && !iszero(x.c)
25+
end
26+
2227
"""
2328
normalize(x::Decimal)
2429

test/test_decimal.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ end
5757

5858
@test isfinite(Decimal(0, 1, 1))
5959
@test !isnan(Decimal(0, 1, 1))
60+
61+
if VERSION v"1.13"
62+
@test ispositive(Decimal(0, 1, 0))
63+
@test !ispositive(Decimal(0, 0, 1))
64+
@test !ispositive(Decimal(1, 1, 0))
65+
66+
@test isnegative(Decimal(1, 1, 0))
67+
@test !isnegative(Decimal(0, 0, 1))
68+
@test !isnegative(Decimal(0, 1, 0))
69+
end
6070
end
6171

6272
@testset "Normalize" begin

0 commit comments

Comments
 (0)