|
284 | 284 | end
|
285 | 285 | end
|
286 | 286 |
|
| 287 | +@testset "neg" begin |
| 288 | + for N in target(Normed; ex = :thin) |
| 289 | + @test wrapping_neg(typemin(N)) === zero(N) |
| 290 | + @test saturating_neg(typemin(N)) === zero(N) |
| 291 | + @test checked_neg(typemin(N)) === zero(N) |
| 292 | + |
| 293 | + @test wrapping_neg(typemax(N)) === eps(N) |
| 294 | + @test saturating_neg(typemax(N)) === zero(N) |
| 295 | + @test_throws OverflowError checked_neg(typemax(N)) |
| 296 | + |
| 297 | + @test wrapping_neg(eps(N)) === typemax(N) |
| 298 | + @test saturating_neg(eps(N)) === zero(N) |
| 299 | + @test_throws OverflowError checked_neg(eps(N)) |
| 300 | + end |
| 301 | + for N in target(Normed, :i8; ex = :thin) |
| 302 | + xs = typemin(N):eps(N):typemax(N) |
| 303 | + fneg(x) = -float(x) |
| 304 | + @test all(x -> wrapping_neg(wrapping_neg(x)) === x, xs) |
| 305 | + @test all(x -> saturating_neg(x) == clamp(fneg(x), N), xs) |
| 306 | + @test all(x -> !(typemin(N) < fneg(x) < typemax(N)) || |
| 307 | + wrapping_neg(x) === checked_neg(x) === fneg(x) % N, xs) |
| 308 | + end |
| 309 | +end |
| 310 | + |
| 311 | +@testset "add" begin |
| 312 | + for N in target(Normed; ex = :thin) |
| 313 | + @test wrapping_add(typemin(N), typemin(N)) === zero(N) |
| 314 | + @test saturating_add(typemin(N), typemin(N)) === zero(N) |
| 315 | + @test checked_add(typemin(N), typemin(N)) === zero(N) |
| 316 | + |
| 317 | + @test wrapping_add(typemax(N), eps(N)) === wrapping_add(eps(N), typemax(N)) === zero(N) |
| 318 | + @test saturating_add(typemax(N), eps(N)) === saturating_add(eps(N), typemax(N)) === typemax(N) |
| 319 | + @test_throws OverflowError checked_add(typemax(N), eps(N)) |
| 320 | + @test_throws OverflowError checked_add(eps(N), typemax(N)) |
| 321 | + |
| 322 | + @test wrapping_add(zero(N), eps(N)) === wrapping_add(eps(N), zero(N)) === eps(N) |
| 323 | + @test saturating_add(zero(N), eps(N)) === saturating_add(eps(N), zero(N)) === eps(N) |
| 324 | + @test checked_add(zero(N), eps(N)) === checked_add(eps(N), zero(N)) === eps(N) |
| 325 | + end |
| 326 | + for N in target(Normed, :i8; ex = :thin) |
| 327 | + xs = typemin(N):eps(N):typemax(N) |
| 328 | + xys = ((x, y) for x in xs, y in xs) |
| 329 | + fadd(x, y) = float(x) + float(y) |
| 330 | + @test all(((x, y),) -> wrapping_sub(wrapping_add(x, y), y) === x, xys) |
| 331 | + @test all(((x, y),) -> saturating_add(x, y) == clamp(fadd(x, y), N), xys) |
| 332 | + @test all(((x, y),) -> !(typemin(N) < fadd(x, y) < typemax(N)) || |
| 333 | + wrapping_add(x, y) === checked_add(x, y) === fadd(x, y) % N, xys) |
| 334 | + end |
| 335 | +end |
| 336 | + |
| 337 | +@testset "sub" begin |
| 338 | + for N in target(Normed; ex = :thin) |
| 339 | + @test wrapping_sub(typemin(N), typemin(N)) === zero(N) |
| 340 | + @test saturating_sub(typemin(N), typemin(N)) === zero(N) |
| 341 | + @test checked_sub(typemin(N), typemin(N)) === zero(N) |
| 342 | + |
| 343 | + @test wrapping_sub(typemin(N), eps(N)) === typemax(N) |
| 344 | + @test saturating_sub(typemin(N), eps(N)) === typemin(N) |
| 345 | + @test_throws OverflowError checked_sub(typemin(N), eps(N)) |
| 346 | + |
| 347 | + @test wrapping_sub(eps(N), zero(N)) === eps(N) |
| 348 | + @test saturating_sub(eps(N), zero(N)) === eps(N) |
| 349 | + @test checked_sub(eps(N), zero(N)) === eps(N) |
| 350 | + end |
| 351 | + for N in target(Normed, :i8; ex = :thin) |
| 352 | + xs = typemin(N):eps(N):typemax(N) |
| 353 | + xys = ((x, y) for x in xs, y in xs) |
| 354 | + fsub(x, y) = float(x) - float(y) |
| 355 | + @test all(((x, y),) -> wrapping_add(wrapping_sub(x, y), y) === x, xys) |
| 356 | + @test all(((x, y),) -> saturating_sub(x, y) == clamp(fsub(x, y), N), xys) |
| 357 | + @test all(((x, y),) -> !(typemin(N) < fsub(x, y) < typemax(N)) || |
| 358 | + wrapping_sub(x, y) === checked_sub(x, y) === fsub(x, y) % N, xys) |
| 359 | + end |
| 360 | +end |
| 361 | + |
287 | 362 | @testset "div/fld1" begin
|
288 | 363 | @test div(reinterpret(N0f8, 0x10), reinterpret(N0f8, 0x02)) == fld(reinterpret(N0f8, 0x10), reinterpret(N0f8, 0x02)) == 8
|
289 | 364 | @test div(reinterpret(N0f8, 0x0f), reinterpret(N0f8, 0x02)) == fld(reinterpret(N0f8, 0x0f), reinterpret(N0f8, 0x02)) == 7
|
|
0 commit comments