Skip to content

Commit 93cec87

Browse files
authored
Merge pull request #74 from nickrobinson251/npr/73-rational-promotion
Fix promotion between FixedDecimal and Rational
2 parents 460eb8f + f4f9494 commit 93cec87

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/FixedPointDecimals.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ end
328328

329329
Base.promote_rule(::Type{FD{T, f}}, ::Type{<:Integer}) where {T, f} = FD{T, f}
330330
Base.promote_rule(::Type{<:FD}, ::Type{TF}) where {TF <: AbstractFloat} = TF
331-
Base.promote_rule(::Type{<:FD}, ::Type{Rational{TR}}) where {TR} = Rational{TR}
331+
Base.promote_rule(::Type{<:FD{T}}, ::Type{Rational{TR}}) where {T, TR} = Rational{promote_type(T, TR)}
332332

333333
# TODO: decide if these are the right semantics;
334334
# right now we pick the bigger int type and the bigger decimal point

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ end
266266
@test 1 + FD2(0.1) === FD2(1.1)
267267
@test FD2(0.1) + FD4(0.0001) === FD4(0.1001)
268268
@test WFD2(0.1) + FD4(0.0001) === WFD4(0.1001)
269+
270+
# promotion with Rational
271+
# see https://github.com/JuliaMath/FixedPointDecimals.jl/issues/73
272+
r = Rational{Int8}(1//1)
273+
fd = FixedDecimal{Int128,4}(2.5806)
274+
@test (r + fd) isa Rational{Int128}
269275
end
270276

271277
@testset "float" begin

0 commit comments

Comments
 (0)