-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed as not planned
Labels
correctness bug ⚠Bugs that are likely to lead to incorrect results in user code without throwingBugs that are likely to lead to incorrect results in user code without throwingduplicateIndicates similar issues or pull requestsIndicates similar issues or pull requestsmathsMathematical functionsMathematical functions
Description
I noticed the following results from isapprox
:
julia> isapprox(1, 2, atol=1)
true
julia> isapprox(UInt(1), UInt(2), atol=1)
false
This function is documented to return true
if the distance between the two inputs is within tolerance bounds, yet it returns false
in the second case despite the fact that the two numbers are distance 1
apart. In fact, it will return false
even if the tolerance is increased:
julia> isapprox(UInt(1), UInt(2), atol=100)
false
julia> isapprox(UInt(1), UInt(2), atol=1_000_000)
false
The same behavior occurs for relative tolerances:
julia> isapprox(1, 2, rtol=1)
true
julia> isapprox(UInt(1), UInt(2), rtol=1)
false
julia> isapprox(UInt(1), UInt(2), rtol=100)
false
julia> isapprox(UInt(1), UInt(2), rtol=1_000_000)
false
Similar behavior can be seen for signed integers, where eg. 125 is considered to be within an absolute distance of 10 from -125:
julia> isapprox(Int8(125), Int8(-125), atol=10)
true
julia> isapprox(Int8(-125), Int8(125), atol=10)
true
This appears to be due to an integer overflow bug in the isapprox implementation for integer arguments. The generic implementation has a comment about avoiding integer overflow but no such accounting is done in the version specialized for integers.
Metadata
Metadata
Assignees
Labels
correctness bug ⚠Bugs that are likely to lead to incorrect results in user code without throwingBugs that are likely to lead to incorrect results in user code without throwingduplicateIndicates similar issues or pull requestsIndicates similar issues or pull requestsmathsMathematical functionsMathematical functions