Skip to content

Commit

Permalink
iszero, isfinite, isnan
Browse files Browse the repository at this point in the history
  • Loading branch information
barucden committed Oct 17, 2024
1 parent 90748c1 commit 88e65fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/decimal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 5 additions & 0 deletions test/test_decimal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 88e65fe

Please sign in to comment.