Skip to content

Commit 415a58c

Browse files
committed
Fix div and friends
1 parent e57195d commit 415a58c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ufixed.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ isinf(x::UFixed) = false
116116
bswap{f}(x::UFixed{UInt8,f}) = x
117117
bswap(x::UFixed) = typeof(x)(bswap(reinterpret(x)),0)
118118

119-
for f in (:div, :fld, :rem, :mod, :mod1, :rem1, :fld1, :min, :max)
119+
for f in (:div, :fld, :fld1)
120+
@eval begin
121+
$f{T<:UFixed}(x::T, y::T) = $f(reinterpret(x),reinterpret(y))
122+
end
123+
end
124+
for f in (:rem, :mod, :mod1, :rem1, :min, :max)
120125
@eval begin
121126
$f{T<:UFixed}(x::T, y::T) = T($f(reinterpret(x),reinterpret(y)),0)
122127
end

test/ufixed.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ for T in (FixedPointNumbers.UF..., UF2...)
133133
testtrunc(eps(T))
134134
end
135135

136+
@test div(0x10uf8, 0x02uf8) == fld(0x10uf8, 0x02uf8) == 8
137+
@test div(0x0fuf8, 0x02uf8) == fld(0x0fuf8, 0x02uf8) == 7
138+
@test Base.fld1(0x10uf8, 0x02uf8) == 8
139+
@test Base.fld1(0x0fuf8, 0x02uf8) == 8
140+
@test mod(0x10uf8, 0x02uf8) == rem(0x10uf8, 0x02uf8) == 0
141+
@test mod(0x0fuf8, 0x02uf8) == rem(0x0fuf8, 0x02uf8) == 0x01uf8
142+
@test mod1(0x10uf8, 0x02uf8) == 0x02uf8
143+
@test mod1(0x0fuf8, 0x02uf8) == 0x01uf8
144+
145+
r = 1uf8:1uf8:48uf8
146+
@test length(r) == 48
147+
136148
# Show
137149
x = 0xaauf8
138150
iob = IOBuffer()

0 commit comments

Comments
 (0)