Skip to content

Commit 0a8e222

Browse files
committed
fixes #34
1 parent add18eb commit 0a8e222

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
@@ -80,8 +80,8 @@ sizeof{T<:UFixed}(::Type{T}) = sizeof(rawtype(T))
8080
abs(x::UFixed) = x
8181

8282
# Arithmetic
83-
*{T,f}(x::UFixed{T,f}, y::UFixed{T,f}) = UFixed{T,f}((Base.widemul(x[],y[]) + (convert(widen(T), 1) << (f-1) ))>>f,0)
84-
/{T,f}(x::UFixed{T,f}, y::UFixed{T,f}) = UFixed{T,f}(div(convert(widen(T), x[])<<f, y[]),0)
83+
*{T<:UFixed}(x::T, y::T) = convert(T,convert(Float32, x)*convert(Float32, y))
84+
/{T<:UFixed}(x::T, y::T) = convert(T,convert(Float32, x)/convert(Float32, y))
8585

8686
# Functions
8787
trunc{T<:UFixed}(x::T) = T(div(x[], rawone(T))*rawone(T),0)

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)