diff --git a/src/decimal.jl b/src/decimal.jl index 11da6ca..4ff71b0 100644 --- a/src/decimal.jl +++ b/src/decimal.jl @@ -65,6 +65,12 @@ end Base.zero(::Type{Decimal}) = Decimal(false, 0, 0) Base.one(::Type{Decimal}) = Decimal(false, 1, 0) +Base.iszero(x::Decimal) = iszero(x.c) + +# As long as we do not support Inf/NaN +Base.isfinite(x::Decimal) = true +Base.isnan(x::Decimal) = false + # convert a decimal to any subtype of Real (::Type{T})(x::Decimal) where {T<:Real} = parse(T, string(x)) diff --git a/test/test_decimal.jl b/test/test_decimal.jl index 57c7c3c..4e2684e 100644 --- a/test/test_decimal.jl +++ b/test/test_decimal.jl @@ -80,4 +80,9 @@ end @test string(number(Decimal(false, 543, -1))) == "54.3" end +@testset "Number functions" begin + @test isfinite(Decimal(0, 1, 1)) + @test !isnan(Decimal(0, 1, 1)) +end + end