@@ -69,6 +69,31 @@ StaticArrays.similar_type(::Union{RotMat2,Type{RotMat2}}) = SMatrix{2,2,Float64,
69
69
end
70
70
end
71
71
72
+ @testset " @fastmath operators" begin
73
+ for T in (Int, Float32, Float64)
74
+ s0 = convert (T, 2 )
75
+ v1 = @SVector T[2 , 4 , 6 , 8 ]
76
+ v2 = @SVector T[4 , 3 , 2 , 1 ]
77
+ m1 = @SMatrix T[2 4 ; 6 8 ]
78
+ m2 = @SMatrix T[4 3 ; 2 1 ]
79
+
80
+ # Use that these small integers can be represetnted exactly
81
+ # as floating point numbers. In general, the comparison of
82
+ # floats should use `≈` instead of `===`.
83
+ # These should be turned into `vfmadd...` calls
84
+ @test @fastmath (@inferred (s0 * v1 + v2)) === @SVector T[8 , 11 , 14 , 17 ]
85
+ @test @fastmath (@inferred (v1 * s0 + v2)) === @SVector T[8 , 11 , 14 , 17 ]
86
+ @test @fastmath (@inferred (s0 * m1 + m2)) === @SMatrix T[8 11 ; 14 17 ]
87
+ @test @fastmath (@inferred (m1 * s0 + m2)) === @SMatrix T[8 11 ; 14 17 ]
88
+
89
+ # These should be turned into `vfmsub...` calls
90
+ @test @fastmath (@inferred (s0 * v1 - v2)) === @SVector T[0 , 5 , 10 , 15 ]
91
+ @test @fastmath (@inferred (v1 * s0 - v2)) === @SVector T[0 , 5 , 10 , 15 ]
92
+ @test @fastmath (@inferred (s0 * m1 - m2)) === @SMatrix T[0 5 ; 10 15 ]
93
+ @test @fastmath (@inferred (m1 * s0 - m2)) === @SMatrix T[0 5 ; 10 15 ]
94
+ end
95
+ end
96
+
72
97
@testset " Interaction with `UniformScaling`" begin
73
98
@test @inferred (@SMatrix ([0 1 ; 2 3 ]) + I) === @SMatrix [1 1 ; 2 4 ]
74
99
@test @inferred (I + @SMatrix ([0 1 ; 2 3 ])) === @SMatrix [1 1 ; 2 4 ]
0 commit comments