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
4 changes: 2 additions & 2 deletions .github/workflows/Invalidations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
lines = readlines("Project.toml")
open("Project.toml", "w") do f
for l in lines
if l == "version = \"0.9.0-dev\""
if startswith(l, "version = ")
l = "version = \"0.8.4\""
end
println(f, l)
Expand All @@ -46,7 +46,7 @@ jobs:
lines = readlines("Project.toml")
open("Project.toml", "w") do f
for l in lines
if l == "version = \"0.9.0-dev\""
if startswith(l, "version = ")
l = "version = \"0.8.4\""
end
println(f, l)
Expand Down
6 changes: 2 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FixedPointNumbers"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.9.0"
version = "0.9.1"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -17,9 +17,7 @@ Aqua = "0.8"
Documenter = "0.27, 1"
Random = "<0.0.1, 1"
StableRNGs = "1"
# Update this version specifier when Statistics.jl v1.11.2 is released.
# https://github.com/JuliaStats/Statistics.jl/issues/165
Statistics = "< 1.11.2"
Statistics = "1"
Test = "1"
julia = "1"

Expand Down
2 changes: 1 addition & 1 deletion src/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ function _rem(x::Fixed, ::Type{F}) where {T, f, F <: Fixed{T,f}}
end
_rem(x::Integer, ::Type{F}) where {T, f, F <: Fixed{T,f}} = F(_unsafe_trunc(T, x) << f, 0)
function _rem(x::Real, ::Type{F}) where {T, f, F <: Fixed{T,f}}
isfinite(x) || return zero(F)
if bitwidth(T) < 32
Ti = T
else
isfinite(x) || return zero(F)
Ti = promote_type(Int64, T)
end
Tf = floattype(F)
Expand Down
6 changes: 4 additions & 2 deletions src/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ _rem(x::N, ::Type{N}) where {N <: Normed} = x
_rem(x::Normed, ::Type{N}) where {T, N <: Normed{T}} =
reinterpret(N, _unsafe_trunc(T, round((rawone(N)/rawone(x))*reinterpret(x))))
function _rem(x::Real, ::Type{N}) where {T, N <: Normed{T}}
bitwidth(T) < 32 || isfinite(x) || return zero(N)
isfinite(x) || return zero(N)
reinterpret(N, _unsafe_trunc(T, round(rawone(N) * x)))
end
_rem(x::Float16, ::Type{X}) where {X <: Normed} = _rem(Float32(x), X) # avoid overflow
Expand Down Expand Up @@ -283,8 +283,10 @@ end
function checked_mul(x::N, y::N) where {T <: Union{UInt8,UInt16,UInt32,UInt64}, f, N <: Normed{T,f}}
f == bitwidth(T) && return wrapping_mul(x, y)
z = widemul(x.i, y.i)
# `rawone(N)` is odd, so `z` rounds to `typemax(N).i` (no overflow) up to
# and including `m`; overflow starts at `m + 1`.
m = widemul(typemax(N).i, rawone(N)) + (rawone(N) >> 0x1)
z < m || throw_overflowerror(:*, x, y)
z <= m || throw_overflowerror(:*, x, y)
N(div_2fm1(z, Val(Int(f))) % T, 0)
end

Expand Down
3 changes: 2 additions & 1 deletion test/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ function test_rem_type(TX::Type)
end

function test_rem_nan(TX::Type)
# TODO: avoid undefined behavior
@testset "nan % $X" for X in target(TX, :i8, :i16, :i32, :i64; ex = :thin)
@test NaN % X === NaN32 % X === NaN16 % X === zero(X)
@test Inf % X === Inf32 % X === Inf16 % X === zero(X)
@test -Inf % X === -Inf32 % X === -Inf16 % X === zero(X)
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ end
@test_throws OverflowError checked_mul(typemax(N), typemax(N))
end
end
# products whose exact value rounds to `typemax` must not throw
@test checked_mul(reinterpret(N1f7, 0x9c), reinterpret(N1f7, 0xd0)) === typemax(N1f7)
@test checked_mul(reinterpret(N7f9, 0x0201), reinterpret(N7f9, 0xff00)) === typemax(N7f9)

test_mul(Normed)
end

Expand Down
Loading