Skip to content
Open
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
4 changes: 1 addition & 3 deletions .github/workflows/JET.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ jobs:
julia --project=. --color=yes -e '
using JET, Test
using FixedPointNumbers
println("report_package(FixedPointNumbers, toplevel_logger=nothing)")
show(JET.report_package(FixedPointNumbers, toplevel_logger=nothing))
@testset "JET" begin
JET.test_package(FixedPointNumbers; target_modules=(FixedPointNumbers,))
JET.test_package(FixedPointNumbers)
Comment thread
PatrickHaecker marked this conversation as resolved.
end'
13 changes: 5 additions & 8 deletions src/FixedPointNumbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,10 @@ clamp(x::X, lo::X, hi::X) where {X <: FixedPoint} = X(clamp(x.i, lo.i, hi.i), 0)

clamp(x, ::Type{X}) where {X <: FixedPoint} = clamp(x, typemin(X), typemax(X)) % X

# Since `FixedPoint` is not an integer type, it is not clear in what type
# `signed` and `unsigned` for `FixedPoint` should return values. They should
# currently throw errors in case we support "unsigned Fixed" or "signed Normed"
# in the future. The following "incomplete" code is necessary for Julia v1.0
# etc. to prevent accidental conversion to an integer type.
signed(x::X) where {X <: FixedPoint} = signed(X)(signed(x.i), 0)
unsigned(x::X) where {X <: FixedPoint} = unsigned(X)(unsigned(x.i), 0)
# Throw a `MethodError` so that the generic fallbacks don't convert a `FixedPoint`
# to an integer type.
signed(x::FixedPoint) = throw(MethodError(signed, (x,)))
unsigned(x::FixedPoint) = throw(MethodError(unsigned, (x,)))

function sign(x::X) where {T, X <: FixedPoint{T}}
T <: Unsigned && return iszero(x) ? x : oneunit(X)
Expand Down Expand Up @@ -657,7 +654,7 @@ function Random.rand(r::AbstractRNG, ::SamplerType{X}) where X <: FixedPoint
end

function rand!(r::AbstractRNG, A::Array{X}, ::SamplerType{X}) where {T, X <: FixedPoint{T}}
At = unsafe_wrap(Array, reinterpret(Ptr{T}, pointer(A)), size(A))
At = unsafe_wrap(Array, Ptr{T}(pointer(A)), size(A))
Comment thread
PatrickHaecker marked this conversation as resolved.
Random.rand!(r, At, SamplerType{T}())
A
end
Expand Down
5 changes: 4 additions & 1 deletion src/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,13 @@ function _trunc(x::Fixed{T,f}) where {T, f}
_rawone = oneunit(T) << f
reinterpret(Fixed{T,f}, (x.i < 0) & (r != 0) ? t + _rawone : t)
end
function _floor(x::Fixed{T,f}) where {T, f}
# The bound `T <: Signed` limits the overlap with the generic `_trunc` for `FixedPoint{<:Unsigned}` to
# `Fixed{Union{}, f}`, which has no values and gets its own method.
function _floor(x::Fixed{T,f}) where {T <: Signed, f}
f == bitwidth(T) && x.i < 0 && throw_converterror(Fixed{T,f}, -1) # TODO: remove this line
Fixed{T,f}(x.i & intmask(x), 0)
end
_floor(x::Fixed{Union{}, f}) where f = throw(MethodError(_floor, (x,)))
function _ceil(x::Fixed{T,f}) where {T, f}
f == 0 && return x
upper = typemax(T) & intmask(x)
Expand Down
Loading