libcruft-util/test/coord/simd.cpp

56 lines
1.3 KiB
C++

#include "coord/simd.hpp"
#include "tap.hpp"
int
main ()
{
using util::coord::simd;
util::TAP::logger tap;
std::clog << "rounding mode is: " << [] () {
switch (_MM_GET_ROUNDING_MODE ()) {
case _MM_ROUND_NEAREST: return "nearest";
case _MM_ROUND_DOWN: return "down";
case _MM_ROUND_UP: return "up";
case _MM_ROUND_TOWARD_ZERO: return "toward_zero";
}
return "unknown";
} () << '\n';
{
const simd a (1,2,3,4);
const simd b (4,1,3,2);
const float res = dot (a, b)[0];
tap.expect_eq (res, 4+2+9+8, "trivial dot product");
}
{
const simd a (1, 2, 3, 4);
const simd b (0, 3, 3, 9);
const auto lo = min (a, b);
const auto hi = max (a, b);
tap.expect_eq (lo, simd {0,2,3,4}, "vector minimum");
tap.expect_eq (hi, simd {1,3,3,9}, "vector maximum");
}
{
const simd val { -INFINITY, INFINITY, 0, -9 };
tap.expect_eq (abs (val), simd {INFINITY,INFINITY,0,9}, "absolute value");
}
{
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");
};
return tap.status ();
}