@@ -779,17 +779,11 @@ end
779
779
@testset " limits: with_overflow math" begin
780
780
# Easy to reason about cases of overflow:
781
781
@test Base. Checked. add_with_overflow (FD {Int8,2} (1 ), FD {Int8,2} (1 )) == (FD {Int8,2} (- 0.56 ), true )
782
- @test Base. Checked. add_with_overflow (FD {Int8,2} (1 ), 1 ) == (FD {Int8,2} (- 0.56 ), true )
782
+ @test Base. Checked. add_with_overflow (FD {Int8,2} (1 ), FD {Int8,2} ( 1 ) ) == (FD {Int8,2} (- 0.56 ), true )
783
783
@test Base. Checked. add_with_overflow (FD {Int8,2} (1 ), FD {Int8,2} (0.4 )) == (FD {Int8,2} (- 1.16 ), true )
784
-
785
784
@test Base. Checked. sub_with_overflow (FD {Int8,2} (1 ), FD {Int8,2} (- 1 )) == (FD {Int8,2} (- 0.56 ), true )
786
- @test Base. Checked. sub_with_overflow (1 , FD {Int8,2} (- 1 )) == (FD {Int8,2} (- 0.56 ), true )
787
785
@test Base. Checked. sub_with_overflow (FD {Int8,2} (- 1 ), FD {Int8,2} (0.4 )) == (FD {Int8,2} (1.16 ), true )
788
-
789
786
@test Base. Checked. mul_with_overflow (FD {Int8,2} (1.2 ), FD {Int8,2} (1.2 )) == (FD {Int8,2} (- 1.12 ), true )
790
- @test Base. Checked. mul_with_overflow (FD {Int8,1} (12 ), 2 ) == (FD {Int8,1} (- 1.6 ), true )
791
- @test Base. Checked. mul_with_overflow (FD {Int8,0} (120 ), 2 ) == (FD {Int8,0} (- 16 ), true )
792
- @test Base. Checked. mul_with_overflow (120 , FD {Int8,0} (2 )) == (FD {Int8,0} (- 16 ), true )
793
787
794
788
@test div_with_overflow (FD {Int8,2} (1 ), FD {Int8,2} (0.5 )) == (FD {Int8,2} (- 0.56 ), true )
795
789
@test div_with_overflow (typemin (FD{Int32,0 }), FD {Int32,0} (- 1 )) == (typemin (FD{Int32,0 }), true )
@@ -802,23 +796,23 @@ end
802
796
803
797
@test Base. Checked. add_with_overflow (typemax (T), eps (T)) == (typemax (T) + eps (T), true )
804
798
issigned (I) && @test Base. Checked. add_with_overflow (typemin (T), - eps (T)) == (typemin (T) + - eps (T), true )
805
- @test Base. Checked. add_with_overflow (typemax (T), 1 ) == (typemax (T) + 1 , true )
806
- @test Base. Checked. add_with_overflow (1 , typemax (T)) == (typemax (T) + 1 , true )
799
+ @test Base. Checked. add_with_overflow (typemax (T), T ( 1 ) ) == (typemax (T) + 1 , true )
800
+ @test Base. Checked. add_with_overflow (T ( 1 ) , typemax (T)) == (typemax (T) + 1 , true )
807
801
808
802
@test Base. Checked. sub_with_overflow (typemin (T), eps (T)) == (typemin (T) - eps (T), true )
809
803
issigned (I) && @test Base. Checked. sub_with_overflow (typemax (T), - eps (T)) == (typemax (T) - - eps (T), true )
810
- @test Base. Checked. sub_with_overflow (typemin (T), 1 ) == (typemin (T) - 1 , true )
804
+ @test Base. Checked. sub_with_overflow (typemin (T), T ( 1 ) ) == (typemin (T) - 1 , true )
811
805
if issigned (I) && 2.0 <= typemax (T)
812
- @test Base. Checked. sub_with_overflow (- 2 , typemax (T)) == (- 2 - typemax (T), true )
806
+ @test Base. Checked. sub_with_overflow (T ( - 2 ) , typemax (T)) == (- 2 - typemax (T), true )
813
807
end
814
808
815
809
@test Base. Checked. mul_with_overflow (typemax (T), typemax (T)) == (typemax (T) * typemax (T), true )
816
810
issigned (I) && @test Base. Checked. mul_with_overflow (typemin (T), typemax (T)) == (typemin (T) * typemax (T), true )
817
811
if 2.0 <= typemax (T)
818
- @test Base. Checked. mul_with_overflow (typemax (T), 2 ) == (typemax (T) * 2 , true )
819
- @test Base. Checked. mul_with_overflow (2 , typemax (T)) == (2 * typemax (T), true )
820
- issigned (I) && @test Base. Checked. mul_with_overflow (typemin (T), 2 ) == (typemin (T) * 2 , true )
821
- issigned (I) && @test Base. Checked. mul_with_overflow (2 , typemin (T)) == (2 * typemin (T), true )
812
+ @test Base. Checked. mul_with_overflow (typemax (T), T ( 2 ) ) == (typemax (T) * 2 , true )
813
+ @test Base. Checked. mul_with_overflow (T ( 2 ) , typemax (T)) == (2 * typemax (T), true )
814
+ issigned (I) && @test Base. Checked. mul_with_overflow (typemin (T), T ( 2 ) ) == (typemin (T) * 2 , true )
815
+ issigned (I) && @test Base. Checked. mul_with_overflow (T ( 2 ) , typemin (T)) == (2 * typemin (T), true )
822
816
end
823
817
824
818
if f > 0
@@ -833,36 +827,21 @@ end
833
827
end
834
828
end
835
829
836
- @testset " with_overflow math promotions" begin
837
- x = FD {Int8,1} (1 )
838
- y = FD {Int64,1} (2 )
839
- @testset for op in (
840
- Base. Checked. add_with_overflow, Base. Checked. sub_with_overflow,
841
- Base. Checked. mul_with_overflow,
842
- )
843
- @test op (x, y) === op (FD {Int64,1} (1 ), y)
844
- @test op (y, x) === op (y, FD {Int64,1} (1 ))
845
-
846
- @test op (x, 2 ) === op (x, FD {Int8,1} (2 ))
847
- @test op (2 , x) === op (FD {Int8,1} (2 ), x)
848
- end
849
- end
850
-
851
830
@testset " non-overflowing with_overflow math" begin
852
- @test Base. Checked. add_with_overflow (1 , FD {Int8,1} (1.1 )) == (FD {Int8,1} (2.1 ), false )
853
- @test Base. Checked. add_with_overflow (FD {Int8,1} (1.1 ), 1 ) == (FD {Int8,1} (2.1 ), false )
831
+ @test Base. Checked. add_with_overflow (FD {Int8,1} ( 1 ) , FD {Int8,1} (1.1 )) == (FD {Int8,1} (2.1 ), false )
832
+ @test Base. Checked. add_with_overflow (FD {Int8,1} (1.1 ), FD {Int8,1} ( 1 ) ) == (FD {Int8,1} (2.1 ), false )
854
833
@test Base. Checked. add_with_overflow (FD {Int64,8} (30.123 ), FD {Int64,8} (30 )) == (FD {Int64,8} (60.123 ), false )
855
- @test Base. Checked. add_with_overflow (FD {Int64,8} (30.123 ), FD {Int64,5} ( 30 )) == (FD {Int64,8} (60.123 ), false )
834
+ @test Base. Checked. add_with_overflow (FD {Int64,8} (30.123 ), FD {Int64,8} ( - 50 )) == (FD {Int64,8} (- 19.877 ), false )
856
835
857
- @test Base. Checked. sub_with_overflow (3 , FD {Int16,2} (2.5 )) == (FD {Int16,1} (0.5 ), false )
858
- @test Base. Checked. sub_with_overflow (FD {Int16,2} (2.5 ), 3 ) == (FD {Int16,1} (- 0.5 ), false )
836
+ @test Base. Checked. sub_with_overflow (FD {Int16,2} ( 3 ) , FD {Int16,2} (2.5 )) == (FD {Int16,1} (0.5 ), false )
837
+ @test Base. Checked. sub_with_overflow (FD {Int16,2} (2.5 ), FD {Int16,2} ( 3 ) ) == (FD {Int16,1} (- 0.5 ), false )
859
838
@test Base. Checked. sub_with_overflow (FD {Int32,4} (10.11 ), FD {Int32,4} (2 )) == (FD {Int32,4} (8.11 ), false )
860
- @test Base. Checked. sub_with_overflow (FD {Int32,4} (10.11 ), FD {Int32,3} ( 2 )) == (FD {Int32,4} (8 .11 ), false )
839
+ @test Base. Checked. sub_with_overflow (FD {Int32,4} (10.11 ), FD {Int32,4} ( - 2 )) == (FD {Int32,4} (12 .11 ), false )
861
840
862
- @test Base. Checked. mul_with_overflow (4 , FD {Int64,6} (2.22 )) == (FD {Int64,6} (8.88 ), false )
863
- @test Base. Checked. mul_with_overflow (FD {Int64,6} (2.22 ), 4 ) == (FD {Int64,6} (8.88 ), false )
841
+ @test Base. Checked. mul_with_overflow (FD {Int64,6} ( 4 ) , FD {Int64,6} (2.22 )) == (FD {Int64,6} (8.88 ), false )
842
+ @test Base. Checked. mul_with_overflow (FD {Int64,6} (2.22 ), FD {Int64,6} ( 4 ) ) == (FD {Int64,6} (8.88 ), false )
864
843
@test Base. Checked. mul_with_overflow (FD {Int128,14} (10 ), FD {Int128,14} (20.1 )) == (FD {Int128,14} (201 ), false )
865
- @test Base. Checked. mul_with_overflow (FD {Int128,30} (10.11 ), FD {Int128,0 } (1 )) == (FD {Int128,30} (10.11 ), false )
844
+ @test Base. Checked. mul_with_overflow (FD {Int128,30} (10.1 ), FD {Int128,30 } (1 )) == (FD {Int128,30} (10.1 ), false )
866
845
867
846
@test div_with_overflow (FD {Int64,6} (4 ), FD {Int64,6} (2 )) == (FD {Int64,6} (2 ), false )
868
847
@test div_with_overflow (FD {Int32,6} (4 ), FD {Int32,6} (2.1 )) == (FD {Int32,6} (1 ), false )
0 commit comments