|
209 | 209 | struct CustomNumber <: Number end
|
210 | 210 | @test !isnan(CustomNumber())
|
211 | 211 | end
|
| 212 | + |
| 213 | +@testset "isapprox and integer overflow" begin |
| 214 | + for T in (Int8, Int16, Int32) |
| 215 | + T === Int && continue |
| 216 | + @test !isapprox(typemin(T), T(0)) |
| 217 | + @test !isapprox(typemin(T), unsigned(T)(0)) |
| 218 | + @test !isapprox(typemin(T), 0) |
| 219 | + @test !isapprox(typemin(T), T(0), atol=0.99) |
| 220 | + @test !isapprox(typemin(T), unsigned(T)(0), atol=0.99) |
| 221 | + @test !isapprox(typemin(T), 0, atol=0.99) |
| 222 | + @test_broken !isapprox(typemin(T), T(0), atol=1) |
| 223 | + @test_broken !isapprox(typemin(T), unsigned(T)(0), atol=1) |
| 224 | + @test !isapprox(typemin(T), 0, atol=1) |
| 225 | + |
| 226 | + @test !isapprox(typemin(T)+T(10), T(10)) |
| 227 | + @test !isapprox(typemin(T)+T(10), unsigned(T)(10)) |
| 228 | + @test !isapprox(typemin(T)+T(10), 10) |
| 229 | + @test !isapprox(typemin(T)+T(10), T(10), atol=0.99) |
| 230 | + @test !isapprox(typemin(T)+T(10), unsigned(T)(10), atol=0.99) |
| 231 | + @test !isapprox(typemin(T)+T(10), 10, atol=0.99) |
| 232 | + @test_broken !isapprox(typemin(T)+T(10), T(10), atol=1) |
| 233 | + @test !isapprox(typemin(T)+T(10), unsigned(T)(10), atol=1) |
| 234 | + @test !isapprox(typemin(T)+T(10), 10, atol=1) |
| 235 | + |
| 236 | + @test isapprox(typemin(T), 0.0, rtol=1) |
| 237 | + end |
| 238 | + for T in (Int, Int64, Int128) |
| 239 | + @test !isapprox(typemin(T), T(0)) |
| 240 | + @test !isapprox(typemin(T), unsigned(T)(0)) |
| 241 | + @test !isapprox(typemin(T), T(0), atol=0.99) |
| 242 | + @test !isapprox(typemin(T), unsigned(T)(0), atol=0.99) |
| 243 | + @test_broken !isapprox(typemin(T), T(0), atol=1) |
| 244 | + @test_broken !isapprox(typemin(T), unsigned(T)(0), atol=1) |
| 245 | + |
| 246 | + @test !isapprox(typemin(T)+T(10), T(10)) |
| 247 | + @test !isapprox(typemin(T)+T(10), unsigned(T)(10)) |
| 248 | + @test !isapprox(typemin(T)+T(10), T(10), atol=0.99) |
| 249 | + @test !isapprox(typemin(T)+T(10), unsigned(T)(10), atol=0.99) |
| 250 | + @test_broken !isapprox(typemin(T)+T(10), T(10), atol=1) |
| 251 | + @test !isapprox(typemin(T)+T(10), unsigned(T)(10), atol=1) |
| 252 | + |
| 253 | + @test isapprox(typemin(T), 0.0, rtol=1) |
| 254 | + end |
| 255 | +end |
0 commit comments