This commit is contained in:
Бранимир Караџић
2021-10-13 19:54:13 -07:00
parent 2eee001125
commit 5dfb7f91f5
4 changed files with 59 additions and 59 deletions

View File

@@ -316,7 +316,7 @@ namespace bx
return _a - _b * floor(_a / _b);
}
inline BX_CONSTEXPR_FUNC bool equal(float _a, float _b, float _epsilon)
inline BX_CONSTEXPR_FUNC bool isEqual(float _a, float _b, float _epsilon)
{
// Reference(s):
// - Floating-point tolerances revisited
@@ -327,12 +327,12 @@ namespace bx
return lhs <= rhs;
}
inline BX_CONST_FUNC bool equal(const float* _a, const float* _b, uint32_t _num, float _epsilon)
inline BX_CONST_FUNC bool isEqual(const float* _a, const float* _b, uint32_t _num, float _epsilon)
{
bool result = equal(_a[0], _b[0], _epsilon);
bool result = isEqual(_a[0], _b[0], _epsilon);
for (uint32_t ii = 1; result && ii < _num; ++ii)
{
result = equal(_a[ii], _b[ii], _epsilon);
result = isEqual(_a[ii], _b[ii], _epsilon);
}
return result;
}
@@ -690,11 +690,11 @@ namespace bx
};
}
inline BX_CONSTEXPR_FUNC bool equal(const Vec3 _a, const Vec3 _b, float _epsilon)
inline BX_CONSTEXPR_FUNC bool isEqual(const Vec3 _a, const Vec3 _b, float _epsilon)
{
return equal(_a.x, _b.x, _epsilon)
&& equal(_a.y, _b.y, _epsilon)
&& equal(_a.z, _b.z, _epsilon)
return isEqual(_a.x, _b.x, _epsilon)
&& isEqual(_a.y, _b.y, _epsilon)
&& isEqual(_a.z, _b.z, _epsilon)
;
}
@@ -1057,12 +1057,12 @@ namespace bx
};
}
inline BX_CONSTEXPR_FUNC bool equal(const Quaternion _a, const Quaternion _b, float _epsilon)
inline BX_CONSTEXPR_FUNC bool isEqual(const Quaternion _a, const Quaternion _b, float _epsilon)
{
return equal(_a.x, _b.x, _epsilon)
&& equal(_a.y, _b.y, _epsilon)
&& equal(_a.z, _b.z, _epsilon)
&& equal(_a.w, _b.w, _epsilon)
return isEqual(_a.x, _b.x, _epsilon)
&& isEqual(_a.y, _b.y, _epsilon)
&& isEqual(_a.z, _b.z, _epsilon)
&& isEqual(_a.w, _b.w, _epsilon)
;
}

View File

@@ -333,10 +333,10 @@ namespace bx
BX_CONST_FUNC float mod(float _a, float _b);
///
BX_CONSTEXPR_FUNC bool equal(float _a, float _b, float _epsilon);
BX_CONSTEXPR_FUNC bool isEqual(float _a, float _b, float _epsilon);
///
BX_CONST_FUNC bool equal(const float* _a, const float* _b, uint32_t _num, float _epsilon);
BX_CONST_FUNC bool isEqual(const float* _a, const float* _b, uint32_t _num, float _epsilon);
///
BX_CONST_FUNC float wrap(float _a, float _wrap);
@@ -448,7 +448,7 @@ namespace bx
BX_CONSTEXPR_FUNC Vec3 rcp(const Vec3 _a);
///
BX_CONSTEXPR_FUNC bool equal(const Vec3 _a, const Vec3 _b, float _epsilon);
BX_CONSTEXPR_FUNC bool isEqual(const Vec3 _a, const Vec3 _b, float _epsilon);
///
void calcTangentFrame(Vec3& _outT, Vec3& _outB, const Vec3 _n);
@@ -523,7 +523,7 @@ namespace bx
BX_CONST_FUNC Quaternion rotateZ(float _az);
///
BX_CONSTEXPR_FUNC bool equal(const Quaternion _a, const Quaternion _b, float _epsilon);
BX_CONSTEXPR_FUNC bool isEqual(const Quaternion _a, const Quaternion _b, float _epsilon);
///
void mtxIdentity(float* _result);

View File

@@ -79,8 +79,8 @@ TEST_CASE("libm", "")
REQUIRE( 13.0f == bx::trunc( 13.89f) );
REQUIRE(-13.0f == bx::trunc(-13.89f) );
REQUIRE(bx::equal( 0.89f, bx::fract( 13.89f), 0.000001f) );
REQUIRE(bx::equal(-0.89f, bx::fract(-13.89f), 0.000001f) );
REQUIRE(bx::isEqual( 0.89f, bx::fract( 13.89f), 0.000001f) );
REQUIRE(bx::isEqual(-0.89f, bx::fract(-13.89f), 0.000001f) );
bx::Error err;
@@ -89,7 +89,7 @@ TEST_CASE("libm", "")
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "ldexp(%f, %d) == %f (expected: %f)\n", xx, yy, bx::ldexp(xx, yy), ::ldexpf(xx, yy) );
REQUIRE(bx::equal(bx::ldexp(xx, yy), ::ldexpf(xx, yy), 0.00001f) );
REQUIRE(bx::isEqual(bx::ldexp(xx, yy), ::ldexpf(xx, yy), 0.00001f) );
}
}
@@ -97,84 +97,84 @@ TEST_CASE("libm", "")
{
bx::write(writer, &err, "exp(%f) == %f (expected: %f)\n", xx, bx::exp(xx), ::expf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::exp(xx), ::expf(xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::exp(xx), ::expf(xx), 0.00001f) );
}
for (float xx = 0.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "rsqrt(%f) == %f (expected: %f)\n", xx, bx::rsqrt(xx), 1.0f/::sqrtf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::rsqrt(xx), 1.0f/::sqrtf(xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::rsqrt(xx), 1.0f/::sqrtf(xx), 0.00001f) );
}
for (float xx = 0.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "sqrt(%f) == %f (expected: %f)\n", xx, bx::sqrt(xx), ::sqrtf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::sqrt(xx), ::sqrtf(xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::sqrt(xx), ::sqrtf(xx), 0.00001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "pow(1.389f, %f) == %f (expected: %f)\n", xx, bx::pow(1.389f, xx), ::powf(1.389f, xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::pow(1.389f, xx), ::powf(1.389f, xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::pow(1.389f, xx), ::powf(1.389f, xx), 0.00001f) );
}
for (float xx = -1.0f; xx < 1.0f; xx += 0.001f)
{
bx::write(writer, &err, "asin(%f) == %f (expected: %f)\n", xx, bx::asin(xx), ::asinf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::asin(xx), ::asinf(xx), 0.0001f) );
REQUIRE(bx::isEqual(bx::asin(xx), ::asinf(xx), 0.0001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "sin(%f) == %f (expected: %f)\n", xx, bx::sin(xx), ::sinf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::sin(xx), ::sinf(xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::sin(xx), ::sinf(xx), 0.00001f) );
}
for (float xx = -1.0f; xx < 1.0f; xx += 0.1f)
{
bx::write(writer, &err, "sinh(%f) == %f (expected: %f)\n", xx, bx::sinh(xx), ::sinhf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::sinh(xx), ::sinhf(xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::sinh(xx), ::sinhf(xx), 0.00001f) );
}
for (float xx = -1.0f; xx < 1.0f; xx += 0.001f)
{
bx::write(writer, &err, "acos(%f) == %f (expected: %f\n)", xx, bx::acos(xx), ::acosf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::acos(xx), ::acosf(xx), 0.0001f) );
REQUIRE(bx::isEqual(bx::acos(xx), ::acosf(xx), 0.0001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "cos(%f) == %f (expected: %f)\n", xx, bx::cos(xx), ::cosf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::cos(xx), ::cosf(xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::cos(xx), ::cosf(xx), 0.00001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "tan(%f) == %f (expected: %f)\n", xx, bx::tan(xx), ::tanf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::tan(xx), ::tanf(xx), 0.001f) );
REQUIRE(bx::isEqual(bx::tan(xx), ::tanf(xx), 0.001f) );
}
for (float xx = -1.0f; xx < 1.0f; xx += 0.1f)
{
bx::write(writer, &err, "tanh(%f) == %f (expected: %f\n", xx, bx::tanh(xx), ::tanhf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::tanh(xx), ::tanhf(xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::tanh(xx), ::tanhf(xx), 0.00001f) );
}
for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
{
bx::write(writer, &err, "atan(%f) == %f (expected: %f)\n", xx, bx::atan(xx), ::atanf(xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::atan(xx), ::atanf(xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::atan(xx), ::atanf(xx), 0.00001f) );
}
for (float yy = -100.0f; yy < 100.0f; yy += 0.1f)
@@ -183,11 +183,11 @@ TEST_CASE("libm", "")
{
bx::write(writer, &err, "atan2(%f, %f) == %f (expected: %f)\n", yy, xx, bx::atan2(yy, xx), ::atan2f(yy, xx) );
REQUIRE(err.isOk() );
REQUIRE(bx::equal(bx::atan2(yy, xx), ::atan2f(yy, xx), 0.00001f) );
REQUIRE(bx::isEqual(bx::atan2(yy, xx), ::atan2f(yy, xx), 0.00001f) );
}
}
REQUIRE(bx::equal(bx::atan2(0.0f, 0.0f), ::atan2f(0.0f, 0.0f), 0.00001f) );
REQUIRE(bx::isEqual(bx::atan2(0.0f, 0.0f), ::atan2f(0.0f, 0.0f), 0.00001f) );
}
TEST_CASE("ToBits", "")
@@ -205,7 +205,7 @@ TEST_CASE("lerp", "")
void mtxCheck(const float* _a, const float* _b)
{
if (!bx::equal(_a, _b, 16, 0.01f) )
if (!bx::isEqual(_a, _b, 16, 0.01f) )
{
DBG("\n"
"A:\n"
@@ -259,13 +259,13 @@ TEST_CASE("quaternion", "")
mtxCheck(mtxQ, mtx);
bx::toAxisAngle(axis, angle, quat);
REQUIRE(bx::equal(axis, bx::Vec3{1.0f, 0.0f, 0.0f}, 0.01f) );
REQUIRE(bx::equal(angle, ax, 0.01f) );
REQUIRE(bx::isEqual(axis, bx::Vec3{1.0f, 0.0f, 0.0f}, 0.01f) );
REQUIRE(bx::isEqual(angle, ax, 0.01f) );
euler = bx::toEuler(quat);
REQUIRE(bx::equal(euler.x, ax, 0.001f) );
REQUIRE(bx::isEqual(euler.x, ax, 0.001f) );
q2 = bx::fromEuler(euler);
REQUIRE(bx::equal(quat, q2, 0.001f) );
REQUIRE(bx::isEqual(quat, q2, 0.001f) );
}
{ // y
@@ -275,12 +275,12 @@ TEST_CASE("quaternion", "")
mtxCheck(mtxQ, mtx);
bx::toAxisAngle(axis, angle, quat);
REQUIRE(bx::equal(axis, bx::Vec3{0.0f, 1.0f, 0.0f}, 0.01f) );
REQUIRE(bx::equal(angle, ay, 0.01f) );
REQUIRE(bx::isEqual(axis, bx::Vec3{0.0f, 1.0f, 0.0f}, 0.01f) );
REQUIRE(bx::isEqual(angle, ay, 0.01f) );
euler = bx::toEuler(quat);
REQUIRE(bx::equal(euler.y, ay, 0.001f) );
REQUIRE(bx::isEqual(euler.y, ay, 0.001f) );
q2 = bx::fromEuler(euler);
REQUIRE(bx::equal(quat, q2, 0.001f) );
REQUIRE(bx::isEqual(quat, q2, 0.001f) );
}
@@ -291,12 +291,12 @@ TEST_CASE("quaternion", "")
mtxCheck(mtxQ, mtx);
bx::toAxisAngle(axis, angle, quat);
REQUIRE(bx::equal(axis, bx::Vec3{0.0f, 0.0f, 1.0f}, 0.01f) );
REQUIRE(bx::equal(angle, az, 0.01f) );
REQUIRE(bx::isEqual(axis, bx::Vec3{0.0f, 0.0f, 1.0f}, 0.01f) );
REQUIRE(bx::isEqual(angle, az, 0.01f) );
euler = bx::toEuler(quat);
REQUIRE(bx::equal(euler.z, az, 0.001f) );
REQUIRE(bx::isEqual(euler.z, az, 0.001f) );
q2 = bx::fromEuler(euler);
REQUIRE(bx::equal(quat, q2, 0.001f) );
REQUIRE(bx::isEqual(quat, q2, 0.001f) );
}
}

View File

@@ -162,10 +162,10 @@ void simd_check_float(
, _0, _1, _2, _3
);
CHECK(bx::equal(c.f[0], _0, 0.0001f) );
CHECK(bx::equal(c.f[1], _1, 0.0001f) );
CHECK(bx::equal(c.f[2], _2, 0.0001f) );
CHECK(bx::equal(c.f[3], _3, 0.0001f) );
CHECK(bx::isEqual(c.f[0], _0, 0.0001f) );
CHECK(bx::isEqual(c.f[1], _1, 0.0001f) );
CHECK(bx::isEqual(c.f[2], _2, 0.0001f) );
CHECK(bx::isEqual(c.f[3], _3, 0.0001f) );
}
void simd_check_float(
@@ -189,14 +189,14 @@ void simd_check_float(
, _0, _1, _2, _3, _4, _5, _6, _7
);
CHECK(bx::equal(c.f[0], _0, 0.0001f) );
CHECK(bx::equal(c.f[1], _1, 0.0001f) );
CHECK(bx::equal(c.f[2], _2, 0.0001f) );
CHECK(bx::equal(c.f[3], _3, 0.0001f) );
CHECK(bx::equal(c.f[4], _4, 0.0001f) );
CHECK(bx::equal(c.f[5], _5, 0.0001f) );
CHECK(bx::equal(c.f[6], _6, 0.0001f) );
CHECK(bx::equal(c.f[7], _7, 0.0001f) );
CHECK(bx::isEqual(c.f[0], _0, 0.0001f) );
CHECK(bx::isEqual(c.f[1], _1, 0.0001f) );
CHECK(bx::isEqual(c.f[2], _2, 0.0001f) );
CHECK(bx::isEqual(c.f[3], _3, 0.0001f) );
CHECK(bx::isEqual(c.f[4], _4, 0.0001f) );
CHECK(bx::isEqual(c.f[5], _5, 0.0001f) );
CHECK(bx::isEqual(c.f[6], _6, 0.0001f) );
CHECK(bx::isEqual(c.f[7], _7, 0.0001f) );
}
void simd_check_string(const char* _str, bx::simd128_t _a)