|
624 | 624 | @test FD{Int8,1}(2) / Int8(20) == FD{Int8,1}(0.1)
|
625 | 625 | end
|
626 | 626 |
|
627 |
| - @testset "limits: overflow" begin |
| 627 | + @testset "limits: overflow checked math" begin |
628 | 628 | # Easy to reason about cases of overflow:
|
629 | 629 | @test_throws OverflowError Base.checked_add(FD{Int8,2}(1), FD{Int8,2}(1))
|
630 | 630 | @test_throws OverflowError Base.checked_add(FD{Int8,2}(1), 1)
|
|
665 | 665 | @test Base.checked_abs(typemax(FD{Int8,2})) == FD{Int8,2}(1.27)
|
666 | 666 | @test Base.checked_neg(typemax(FD{Int8,2})) == FD{Int8,2}(-1.27)
|
667 | 667 |
|
668 |
| - @testset "Overflow corner cases" begin |
| 668 | + @testset "checked math corner cases" begin |
669 | 669 | @testset for I in (Int128, UInt128, Int8, UInt8), f in (0,2)
|
670 | 670 | T = FD{I, f}
|
671 | 671 | issigned(I) = signed(I) === I
|
|
715 | 715 | issigned(I) && @test_throws OverflowError Base.checked_neg(typemin(T))
|
716 | 716 | end
|
717 | 717 | end
|
| 718 | + |
| 719 | + @testset "checked math promotions" begin |
| 720 | + x = FD{Int8,1}(1) |
| 721 | + y = FD{Int64,1}(2) |
| 722 | + @testset for op in ( |
| 723 | + Base.checked_add, Base.checked_sub, Base.checked_mul, Base.checked_div, |
| 724 | + Base.checked_cld, Base.checked_fld, Base.checked_rem, Base.checked_mod, |
| 725 | + FixedPointDecimals.checked_decimal_division, |
| 726 | + ) |
| 727 | + @test op(x, y) === op(FD{Int64,1}(1), y) |
| 728 | + @test op(y, x) === op(y, FD{Int64,1}(1)) |
| 729 | + |
| 730 | + @test op(x, 2) === op(x, FD{Int8,1}(2)) |
| 731 | + @test op(2, x) === op(FD{Int8,1}(2), x) |
| 732 | + end |
| 733 | + end |
718 | 734 | end
|
719 | 735 |
|
720 | 736 | @testset "limits of $T" for T in CONTAINER_TYPES
|
|
0 commit comments