diff --git a/src/decimal.jl b/src/decimal.jl index 1cc05c2..b4e4889 100644 --- a/src/decimal.jl +++ b/src/decimal.jl @@ -19,6 +19,11 @@ Base.iszero(x::Decimal) = iszero(x.c) Base.isfinite(x::Decimal) = true Base.isnan(x::Decimal) = false +if VERSION ≥ v"1.13" + Base.ispositive(x::Decimal) = !x.s && !iszero(x.c) + Base.isnegative(x::Decimal) = x.s && !iszero(x.c) +end + """ normalize(x::Decimal) diff --git a/test/test_decimal.jl b/test/test_decimal.jl index 5d067d7..dc2988e 100644 --- a/test/test_decimal.jl +++ b/test/test_decimal.jl @@ -57,6 +57,16 @@ end @test isfinite(Decimal(0, 1, 1)) @test !isnan(Decimal(0, 1, 1)) + + if VERSION ≥ v"1.13" + @test ispositive(Decimal(0, 1, 0)) + @test !ispositive(Decimal(0, 0, 1)) + @test !ispositive(Decimal(1, 1, 0)) + + @test isnegative(Decimal(1, 1, 0)) + @test !isnegative(Decimal(0, 0, 1)) + @test !isnegative(Decimal(0, 1, 0)) + end end @testset "Normalize" begin