libcruft-util/test/coord/simd.cpp

45 lines
1019 B
C++
Raw Normal View History

2018-03-16 11:10:44 +11:00
#include "coord/simd.hpp"
#include "tap.hpp"
int
main ()
{
2018-03-20 13:30:05 +11:00
using util::coord::simd;
2018-03-16 11:10:44 +11:00
util::TAP::logger tap;
{
2018-03-20 13:30:05 +11:00
const simd a (1,2,3,4);
const simd b (4,1,3,2);
const float res = dot (a, b)[0];
2018-03-16 11:10:44 +11:00
tap.expect_eq (res, 4+2+9+8, "trivial dot product");
}
{
2018-03-20 13:30:05 +11:00
const simd a (1, 2, 3, 4);
const simd b (0, 3, 3, 9);
2018-03-16 11:10:44 +11:00
const auto lo = min (a, b);
const auto hi = max (a, b);
2018-03-20 13:30:05 +11:00
tap.expect_eq (lo, simd {0,2,3,4}, "vector minimum");
tap.expect_eq (hi, simd {1,3,3,9}, "vector maximum");
2018-03-16 11:10:44 +11:00
}
{
2018-03-20 13:30:05 +11:00
const simd val { -INFINITY, INFINITY, 0, -9 };
tap.expect_eq (abs (val), simd {INFINITY,INFINITY,0,9}, "absolute value");
2018-03-16 11:10:44 +11:00
}
2018-03-20 13:30:05 +11:00
{
const simd test { -1.25f, 1.25f, 0.f, 1.f };
const auto lo = floor (test);
const auto hi = ceil (test);
tap.expect_eq (lo, simd { -2, 1, 0, 1 }, "floor");
tap.expect_eq (hi, simd { -1, 2, 0, 1 }, "ceil");
};
2018-03-16 11:10:44 +11:00
return tap.status ();
}