Skip to content

Commit 8302a1b

Browse files
committed
fixes #34
1 parent 34d7fec commit 8302a1b

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/ufixed.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ abs(x::UFixed) = x
8585

8686
+{T,f}(x::UFixed{T,f}, y::UFixed{T,f}) = UFixed{T,f}(convert(T, x.i+y.i),0)
8787
-{T,f}(x::UFixed{T,f}, y::UFixed{T,f}) = UFixed{T,f}(convert(T, x.i-y.i),0)
88-
*{T,f}(x::UFixed{T,f}, y::UFixed{T,f}) = UFixed{T,f}((Base.widemul(x.i,y.i) + (convert(widen(T), 1) << (f-1) ))>>f,0)
89-
/{T,f}(x::UFixed{T,f}, y::UFixed{T,f}) = UFixed{T,f}(div(convert(widen(T), x.i)<<f, y.i),0)
88+
*{T<:UFixed}(x::T, y::T) = convert(T,convert(Float32, x)*convert(Float32, y))
89+
/{T<:UFixed}(x::T, y::T) = convert(T,convert(Float32, x)/convert(Float32, y))
9090

9191
# Comparisons
9292
<{T<:UFixed}(x::T, y::T) = reinterpret(x) < reinterpret(y)

test/ufixed.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using FixedPointNumbers, Base.Test
2020
for T in FixedPointNumbers.UF
2121
@test zero(T) == 0
2222
@test one(T) == 1
23+
@test one(T) * one(T) == one(T)
2324
@test typemin(T) == 0
2425
@test realmin(T) == 0
2526
@test eps(zero(T)) == eps(typemax(T))
@@ -78,11 +79,7 @@ for T in FixedPointNumbers.UF
7879
@test_approx_eq((x+y)-x, fy)
7980
@test_approx_eq((x-y)+y, fx)
8081
@test_approx_eq(x*y, convert(T, fx*fy))
81-
if T == UFixed14
82-
@test convert(T, fx/fy) - x/y == eps(T)
83-
else
84-
@test_approx_eq(x/y, convert(T, fx/fy))
85-
end
82+
@test_approx_eq(x/y, convert(T, fx/fy))
8683
@test_approx_eq(x^2, convert(T, fx^2))
8784
@test_approx_eq(x^2.1f0, fx^2.1f0)
8885
@test_approx_eq(x^2.1, convert(Float64, x)^2.1)

0 commit comments

Comments
 (0)