Skip to content

Commit

Permalink
Add more tests for isapprox with mixed integer types
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Sep 20, 2024
1 parent d0f7afe commit b8c5962
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,24 @@ end

@testset "isapprox and unsigned integers" begin
for T in Base.BitUnsigned_types
# Test also combinations of different integer types
W = widen(T)
# The order of the operands for difference between unsigned integers is
# very important, test both combinations.
@test isapprox(T(42), T(42); rtol=T(0), atol=0.5)
@test isapprox(T(42), W(42); rtol=T(0), atol=0.5)
@test !isapprox(T(0), T(1); rtol=T(0), atol=0.5)
@test !isapprox(T(1), T(0); rtol=T(0), atol=0.5)
@test isapprox(T(1), T(3); atol=T(2))
@test isapprox(T(4), T(2); atol=T(2))
@test isapprox(T(1), W(3); atol=T(2))
@test isapprox(T(4), W(2); atol=T(2))
@test isapprox(T(5), T(7); atol=typemax(T))
@test isapprox(T(8), T(6); atol=typemax(T))
@test isapprox(T(1), T(2); rtol=1)
@test isapprox(T(6), T(3); rtol=1)
@test isapprox(T(1), W(2); rtol=1)
@test isapprox(T(6), W(3); rtol=1)
@test !isapprox(typemin(T), typemax(T))
@test !isapprox(typemax(T), typemin(T))
@test !isapprox(typemin(T), typemax(T); atol=typemax(T)-T(1))
Expand Down

0 comments on commit b8c5962

Please sign in to comment.