|
791 | 791 | @test Base.Checked.mul_with_overflow(FD{Int8,0}(120), 2) == (FD{Int8,0}(-16), true)
|
792 | 792 | @test Base.Checked.mul_with_overflow(120, FD{Int8,0}(2)) == (FD{Int8,0}(-16), true)
|
793 | 793 |
|
| 794 | + @test div_with_overflow(FD{Int8,2}(1), FD{Int8,2}(0.5)) == (FD{Int8,2}(-0.56), true) |
| 795 | + @test div_with_overflow(typemin(FD{Int32,0}), FD{Int32,0}(-1)) == (typemin(FD{Int32,0}), true) |
| 796 | + @test div_with_overflow(FD{Int16,1}(1639), FD{Int16,1}(0.5)) == (FD{Int16,1}(-3275.6), true) |
| 797 | + |
794 | 798 | @testset "with_overflow math corner cases" begin
|
795 | 799 | @testset for I in (Int128, UInt128, Int8, UInt8), f in (0,2)
|
796 | 800 | T = FD{I, f}
|
|
816 | 820 | issigned(I) && @test Base.Checked.mul_with_overflow(typemin(T), 2) == (typemin(T) * 2, true)
|
817 | 821 | issigned(I) && @test Base.Checked.mul_with_overflow(2, typemin(T)) == (2 * typemin(T), true)
|
818 | 822 | end
|
| 823 | + |
| 824 | + if f > 0 |
| 825 | + @test div_with_overflow(typemax(T), eps(T))[2] |
| 826 | + issigned(I) && @test div_with_overflow(typemin(T), eps(T))[2] |
| 827 | + issigned(I) && @test div_with_overflow(typemax(T), -eps(T))[2] |
| 828 | + |
| 829 | + issigned(I) && @test_throws DivideError div_with_overflow(typemax(T), T(0)) |
| 830 | + issigned(I) && @test_throws DivideError div_with_overflow(typemin(T), T(0)) |
| 831 | + issigned(I) && @test div_with_overflow(typemin(T), -eps(T))[2] |
| 832 | + end |
819 | 833 | end
|
820 | 834 | end
|
821 | 835 |
|
|
849 | 863 | @test Base.Checked.mul_with_overflow(FD{Int64,6}(2.22), 4) == (FD{Int64,6}(8.88), false)
|
850 | 864 | @test Base.Checked.mul_with_overflow(FD{Int128,14}(10), FD{Int128,14}(20.1)) == (FD{Int128,14}(201), false)
|
851 | 865 | @test Base.Checked.mul_with_overflow(FD{Int128,30}(10.11), FD{Int128,0}(1)) == (FD{Int128,30}(10.11), false)
|
| 866 | + |
| 867 | + @test div_with_overflow(FD{Int64,6}(4), FD{Int64,6}(2)) == (FD{Int64,6}(2), false) |
| 868 | + @test div_with_overflow(FD{Int32,6}(4), FD{Int32,6}(2.1)) == (FD{Int32,6}(1), false) |
| 869 | + @test div_with_overflow(FD{Int128,14}(10), FD{Int128,14}(20.1)) == (FD{Int128,14}(0), false) |
| 870 | + @test div_with_overflow(FD{Int128,30}(10.1), FD{Int128,30}(1)) == (FD{Int128,30}(10), false) |
| 871 | + @test div_with_overflow(typemin(FD{Int32,8}(1)), FD{Int32,8}(-1)) == (21, false) |
852 | 872 | end
|
853 | 873 | end
|
854 | 874 |
|
|
0 commit comments