Skip to content

Commit

Permalink
Merge pull request #17 from invenia/big-promote
Browse files Browse the repository at this point in the history
Fix promotion stack overflows with Base Big* types
  • Loading branch information
tinybike authored Dec 21, 2017
2 parents 61b23a4 + 6bc010a commit be5eacc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Base.promote_rule(::Type{Decimal}, ::Type{<:Real}) = Decimal

# override definitions in Base
Base.promote_rule(::Type{BigFloat}, ::Type{Decimal}) = Decimal
Base.promote_rule(::Type{BigInt}, ::Type{Decimal}) = Decimal

# Addition
# To add, convert both decimals to the same exponent.
# (If the exponents are different, use the smaller exponent
Expand Down
8 changes: 8 additions & 0 deletions test/test_equals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ end

@test Decimal(1, 2, 0) == -2
@test Decimal(1, 2, 0) != 2

bf_pi = BigFloat(pi)
@test Decimal(bf_pi) == bf_pi
@test bf_pi == Decimal(bf_pi)

bi = big"4608230166434464229556241992703"
@test Decimal(bi) == bi
@test bi == Decimal(bi)
end

@testset "<" begin
Expand Down

0 comments on commit be5eacc

Please sign in to comment.