improve vector operations when using implicit conversion

It used to be that operations e.g. like:

 float3{} + double{} would be computed as
 float3{} + float3{double{}} instead of
 float3{} + double3{double{}}

I other words, when an implicit conversion was involved on the right
it would be converted to the left side’s type, possibly losing 
precision.

Another problem was that swiping the operands could produce different
Results, e.g.:

   float3{1} * 5.0 -> float3{5.0f}
   5.0 * float3{1} -> double3{5.0}


This is no longer the case, now both expressions would return a double3. 

Note:

float3 r{};
r *= 5;

Is now equivalent to:

r[0] *= 5;
r[1] *= 5;
r[2] *= 5;

Instead of before:

r[0] *= 5.0f;
r[1] *= 5.0f;
r[2] *= 5.0f;
This commit is contained in:
Mathias Agopian
2019-09-18 15:22:02 -07:00
committed by Mathias Agopian
parent 2f5927d531
commit 21acf53d3f
2 changed files with 51 additions and 82 deletions

View File

@@ -31,6 +31,8 @@ TEST_F(VecTest, Constexpr) {
constexpr float2 A2 = a;
constexpr float2 B2 = { a, a };
constexpr float2 C2 = A2;
constexpr float2 E2 = A2 + 0.5f;
constexpr float2 F2 = A2 + 0.5 - 1.0 + (1 + A2);
constexpr float3 D2 = cross(A2, C2);
constexpr float3 A3 = a;
@@ -64,7 +66,8 @@ TEST_F(VecTest, Constexpr) {
constexpr float4 S0 = A4 + B4;
constexpr float4 S1 = C4 - D4;
constexpr float4 S2 = A4 * a;
constexpr float4 S2 = (a * A4) + (A4 * a);
constexpr float4 S7 = (a / A4) + (A4 / a);
constexpr float4 S3 = A4 * A4;
constexpr float4 S4 = A4 / a;
constexpr float4 S5 = A4 / A4;