-
Notifications
You must be signed in to change notification settings - Fork 32
Closed
Description
For example,
julia> isapprox(-0.25Q0f7, -0.5Q0f7, rtol=0.5, atol=0) # this is OK
true
julia> isapprox(-0.5Q0f7, -1Q0f7, rtol=0.5, atol=0)
false
julia> isapprox(-0.5, -1.0, rtol=0.5, atol=0)
true
The direct cause is an overflow within abs
.
FixedPointNumbers.jl/src/FixedPointNumbers.jl
Lines 93 to 97 in 3e41a6a
function isapprox(x::T, y::T; rtol=0, atol=max(eps(x), eps(y))) where {T <: FixedPoint} | |
maxdiff = T(atol+rtol*max(abs(x), abs(y))) | |
rx, ry, rd = reinterpret(x), reinterpret(y), reinterpret(maxdiff) | |
abs(signed(widen1(rx))-signed(widen1(ry))) <= rd | |
end |
julia> abs(-1Q0f7)
-1.0Q0f7
julia> abs(Int8(-128))
-128
I don't think this is a critical issue, but I plan to add checked_abs
/ saturating_abs
after PR #190. Also, in the future, the default arithmetic may be changed to the checked arithmetic.
timholy
Metadata
Metadata
Assignees
Labels
No labels