Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ufixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ isinf(x::UFixed) = false
bswap{f}(x::UFixed{UInt8,f}) = x
bswap(x::UFixed) = typeof(x)(bswap(reinterpret(x)),0)

for f in (:div, :fld, :rem, :mod, :mod1, :rem1, :fld1, :min, :max)
for f in (:div, :fld, :fld1)
@eval begin
$f{T<:UFixed}(x::T, y::T) = $f(reinterpret(x),reinterpret(y))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what confuses me. The result type here is now an unsigned integer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you arguing we should throw an InexactError?

end
end
for f in (:rem, :mod, :mod1, :rem1, :min, :max)
@eval begin
$f{T<:UFixed}(x::T, y::T) = T($f(reinterpret(x),reinterpret(y)),0)
end
Expand Down
12 changes: 12 additions & 0 deletions test/ufixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ for T in (FixedPointNumbers.UF..., UF2...)
testtrunc(eps(T))
end

@test div(0x10uf8, 0x02uf8) == fld(0x10uf8, 0x02uf8) == 8
@test div(0x0fuf8, 0x02uf8) == fld(0x0fuf8, 0x02uf8) == 7
@test Base.fld1(0x10uf8, 0x02uf8) == 8
@test Base.fld1(0x0fuf8, 0x02uf8) == 8
@test mod(0x10uf8, 0x02uf8) == rem(0x10uf8, 0x02uf8) == 0
@test mod(0x0fuf8, 0x02uf8) == rem(0x0fuf8, 0x02uf8) == 0x01uf8
@test mod1(0x10uf8, 0x02uf8) == 0x02uf8
@test mod1(0x0fuf8, 0x02uf8) == 0x01uf8

r = 1uf8:1uf8:48uf8
@test length(r) == 48

# Show
x = 0xaauf8
iob = IOBuffer()
Expand Down