|
386 | 386 | @test nthroot(interval(BigFloat, -81, -16), -4) ≛ ∅
|
387 | 387 | @test nthroot(interval(BigFloat, -81, -16), 1) ≛ interval(BigFloat, -81, -16)
|
388 | 388 | end
|
| 389 | + |
| 390 | +# approximation used for testing (not to rely on ≈ for intervals) |
| 391 | +# ⪆(x, y) = (x ≈ y) && (x ⊇ y) |
| 392 | +⪆(x::Interval, y::Interval) = x.lo ≈ y.lo && x.hi ≈ y.hi && x ⊇ y |
| 393 | + |
| 394 | +@testset "`mod`" begin |
| 395 | + r = 0.0625 |
| 396 | + x = r..(1+r) |
| 397 | + @test mod(x, 1) == mod(x, 1.0) == 0..1 |
| 398 | + @test mod(x, 2) == mod(x, 2.0) ⪆ x |
| 399 | + @test mod(x, 2.5) ⪆ x |
| 400 | + @test mod(x, 0.5) == 0..0.5 |
| 401 | + @test mod(x, -1) == mod(x, -1.0) == -1..0 |
| 402 | + @test mod(x, -2) == mod(x, -2.0) ⪆ -2+x |
| 403 | + @test mod(x, -2.5) ⪆ -2.5+x |
| 404 | + @test mod(x, -0.5) == -0.5..0 |
| 405 | + |
| 406 | + x = (-1+r) .. -r |
| 407 | + @test mod(x, 1) == mod(x, 1.0) ⪆ 1+x |
| 408 | + @test mod(x, 2) == mod(x, 2.0) ⪆ 2+x |
| 409 | + @test mod(x, 2.5) ⪆ 2.5+x |
| 410 | + @test mod(x, 0.5) == 0..0.5 |
| 411 | + @test mod(x, -1) == mod(x, -1.0) ⪆ x |
| 412 | + @test mod(x, -2) == mod(x, -2.0) ⪆ x |
| 413 | + @test mod(x, -2.5) ⪆ x |
| 414 | + @test mod(x, -0.5) == -0.5..0 |
| 415 | + |
| 416 | + x = -r .. 1-r |
| 417 | + @test mod(x, 1) == mod(x, 1.0) == 0..1 |
| 418 | + @test mod(x, 2) == mod(x, 2.0) == 0..2 |
| 419 | + @test mod(x, 2.5) == 0..2.5 |
| 420 | + @test mod(x, 0.5) == 0..0.5 |
| 421 | + @test mod(x, -1) == mod(x, -1.0) == -1..0 |
| 422 | + @test mod(x, -2) == mod(x, -2.0) == -2..0 |
| 423 | + @test mod(x, -2.5) == -2.5..0 |
| 424 | + @test mod(x, -0.5) == -0.5..0 |
| 425 | + |
| 426 | + # TODO - implement mod for two intervals |
| 427 | + @test_throws ArgumentError mod(1..2, 1.4..1.5) |
| 428 | + @test_throws ArgumentError mod(1.0, 1.4..1.5) |
| 429 | +end |
0 commit comments