Skip to content

Commit 0131751

Browse files
committed
Add a missing rem method
1 parent fe244dd commit 0131751

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

src/ufixed.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ _convert{U<:UFixed }(::Type{U}, ::Type{UInt128}, x) = U(round(UInt128, rawone(U
5050
rem{T<:UFixed}(x::T, ::Type{T}) = x
5151
rem{T<:UFixed}(x::UFixed, ::Type{T}) = reinterpret(T, unsafe_trunc(rawtype(T), round((rawone(T)/rawone(x))*reinterpret(x))))
5252
rem{T<:UFixed}(x::Real, ::Type{T}) = reinterpret(T, unsafe_trunc(rawtype(T), round(rawone(T)*x)))
53+
rem{T<:UFixed}(x::Integer, ::Type{T}) = reinterpret(T, (rawone(T)*x) % rawtype(T)) # can be deleted once unsafe_trunc supports integer types (julia #18629)
5354

5455
convert(::Type{BigFloat}, x::UFixed) = reinterpret(x)*(1/BigFloat(rawone(x)))
5556
function convert{T<:AbstractFloat}(::Type{T}, x::UFixed)

test/ufixed.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ end
9393
@test (65.2 % UFixed10).i == round(Int, 65.2*1023) % UInt16
9494
@test (-0.3 % UFixed10).i == round(Int, -0.3*1023) % UInt16
9595

96+
@test 1 % UFixed8 == 1
97+
@test 2 % UFixed8 == UFixed8(0.996)
98+
9699
x = UFixed8(0b01010001, 0)
97100
@test ~x == UFixed8(0b10101110, 0)
98101
@test -x == 0xafuf8

0 commit comments

Comments
 (0)