Skip to content

Commit cab7382

Browse files
committed
Fix reductions so they don't overflow
1 parent 4c30ba6 commit cab7382

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/FixedPointNumbers.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ include("ufixed.jl")
6060
include("deprecations.jl")
6161

6262

63+
# Promotions for reductions
64+
for F in (Base.AddFun, Base.MulFun)
65+
@eval Base.r_promote{T}(::$F, x::FixedPoint{T}) = Float64(x)
66+
end
67+
6368
# TODO: rewrite this by @generated
6469
for T in tuple(Fixed16, UF...)
6570
R = rawtype(T)

test/ufixed.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@ b, ad = scaledual(0.5, ad)
153153
generic_scale!(rfloat, a, 0.5)
154154
generic_scale!(rfixed, ad, b)
155155
@test rfloat == rfixed
156+
157+
a = UFixed8[0xffuf8, 0xffuf8]
158+
@test sum(a) == 2.0

0 commit comments

Comments
 (0)