|
257 | 257 | end
|
258 | 258 | end
|
259 | 259 |
|
| 260 | +@testset "isapprox and unsigned integers" begin |
| 261 | + for T in Base.BitUnsigned_types |
| 262 | + # Test also combinations of different integer types |
| 263 | + W = widen(T) |
| 264 | + # The order of the operands for difference between unsigned integers is |
| 265 | + # very important, test both combinations. |
| 266 | + @test isapprox(T(42), T(42); rtol=T(0), atol=0.5) |
| 267 | + @test isapprox(T(42), W(42); rtol=T(0), atol=0.5) |
| 268 | + @test !isapprox(T(0), T(1); rtol=T(0), atol=0.5) |
| 269 | + @test !isapprox(T(1), T(0); rtol=T(0), atol=0.5) |
| 270 | + @test isapprox(T(1), T(3); atol=T(2)) |
| 271 | + @test isapprox(T(4), T(2); atol=T(2)) |
| 272 | + @test isapprox(T(1), W(3); atol=T(2)) |
| 273 | + @test isapprox(T(4), W(2); atol=T(2)) |
| 274 | + @test isapprox(T(5), T(7); atol=typemax(T)) |
| 275 | + @test isapprox(T(8), T(6); atol=typemax(T)) |
| 276 | + @test isapprox(T(1), T(2); rtol=1) |
| 277 | + @test isapprox(T(6), T(3); rtol=1) |
| 278 | + @test isapprox(T(1), W(2); rtol=1) |
| 279 | + @test isapprox(T(6), W(3); rtol=1) |
| 280 | + @test !isapprox(typemin(T), typemax(T)) |
| 281 | + @test !isapprox(typemax(T), typemin(T)) |
| 282 | + @test !isapprox(typemin(T), typemax(T); atol=typemax(T)-T(1)) |
| 283 | + @test !isapprox(typemax(T), typemin(T); atol=typemax(T)-T(1)) |
| 284 | + @test isapprox(typemin(T), typemax(T); atol=typemax(T)) |
| 285 | + @test isapprox(typemax(T), typemin(T); atol=typemax(T)) |
| 286 | + end |
| 287 | +end |
| 288 | + |
260 | 289 | @testset "Conversion from floating point to unsigned integer near extremes (#51063)" begin
|
261 | 290 | @test_throws InexactError UInt32(4.2949673f9)
|
262 | 291 | @test_throws InexactError UInt64(1.8446744f19)
|
|
0 commit comments