Skip to content

Commit

Permalink
Merge pull request #271 from ABRG-Models/constexpr_units
Browse files Browse the repository at this point in the history
Demonstrates that += and -= are ok in constexpr fn
  • Loading branch information
sebjameswml authored Oct 21, 2024
2 parents 449eba7 + 3f1eef4 commit dd046d8
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/testvec_constexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ constexpr morph::vec<double, 3> vec_add()
return vce;
}

constexpr morph::vec<double, 3> vec_plusequals()
{
constexpr morph::vec<double, 3> v1 = { 1.0, 2.0, 3.0 };
morph::vec<double, 3> v2 = { 1.0, 2.0, 3.0 };
v2 += v1;
return v2;
}

constexpr morph::vec<double, 3> vec_subtract()
{
morph::vec<double, 3> v1 = { 1.0, 2.0, 3.0 };
morph::vec<double, 3> v2 = { 1.0, 2.0, 3.0 };
morph::vec<double, 3> vce = v1 - v2;
return vce;
}

constexpr morph::vec<double, 3> vec_subtractequals()
{
constexpr morph::vec<double, 3> v1 = { 1.0, 2.0, 3.0 };
morph::vec<double, 3> v2 = { 1.0, 2.0, 3.0 };
v2 -= v1;
return v2;
}

constexpr morph::vec<double, 3> vec_div_scalar()
{
morph::vec<double, 3> v1 = { 1.0, 2.0, 3.0 };
Expand All @@ -43,7 +67,7 @@ constexpr morph::vec<double, 3> vec_div_vec()
constexpr morph::vec<double, 3> vec_diveq_vec()
{
morph::vec<double, 3> v1 = { 1.0, 2.0, 3.0 };
morph::vec<double, 3> v2 = { 2.0, 2.0, 2.0 };
constexpr morph::vec<double, 3> v2 = { 2.0, 2.0, 2.0 };
v1 /= v2;
return v1;
}
Expand Down Expand Up @@ -405,6 +429,9 @@ int main()
constexpr morph::vec<double, 3> result1 = vec_add();
if (result1[0] != 2.0) { std::cout << "Fail 1\n"; rtn -= 1; }

constexpr morph::vec<double, 3> result1_1 = vec_plusequals();
if (result1_1[0] != 2.0) { std::cout << "Fail 1_1\n"; rtn -= 1; }

constexpr morph::vec<double, 3> result2 = vec_div_scalar();
if (result2[0] != 1.0/2.0) { std::cout << "Fail 2\n"; rtn -= 1; }

Expand Down Expand Up @@ -508,5 +535,11 @@ int main()
constexpr morph::vec<float, 2> result34 = vec_angle();
if (result34[0] != std::sqrt(2.0f)/2.0f) { std::cout << "Fail 34\n"; rtn -= 1; }

constexpr morph::vec<double, 3> result35 = vec_subtract();
if (result35[0] != 0.0) { std::cout << "Fail 35\n"; rtn -= 1; }

constexpr morph::vec<double, 3> result36 = vec_subtractequals();
if (result36[0] != 0.0) { std::cout << "Fail 36\n"; rtn -= 1; }

return rtn;
}

0 comments on commit dd046d8

Please sign in to comment.