From 45b57cc102fb534d0f76167b2d7dd9fd301013d3 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 31 May 2015 19:52:09 +0000 Subject: [PATCH] math: rename re() to inverse() in all classes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The name “re” came from “reciprocal” but since we have “inverse” for matrices, I thought it would be nice to make everything consistent. --- src/lol/math/real.h | 6 +++--- src/lol/math/transform.h | 14 +++++++------- src/math/real.cpp | 18 +++++++++--------- src/t/math/cmplx.cpp | 4 ++-- src/t/math/quat.cpp | 4 ++-- src/t/math/real.cpp | 4 ++-- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/lol/math/real.h b/src/lol/math/real.h index c4007cd1..f99a144c 100644 --- a/src/lol/math/real.h +++ b/src/lol/math/real.h @@ -111,7 +111,7 @@ public: template friend Real nextafter(Real const &x, Real const &y); /* Power functions */ - template friend Real re(Real const &x); + template friend Real inverse(Real const &x); template friend Real sqrt(Real const &x); template friend Real cbrt(Real const &x); template friend Real pow(Real const &x, Real const &y); @@ -270,7 +270,7 @@ template Real ldexp(Real const &x, int exp); template Real modf(Real const &x, Real *iptr); template Real ulp(Real const &x); template Real nextafter(Real const &x, Real const &y); -template Real re(Real const &x); +template Real inverse(Real const &x); template Real sqrt(Real const &x); template Real cbrt(Real const &x); template Real pow(Real const &x, Real const &y); @@ -310,7 +310,7 @@ template<> real ldexp(real const &x, int exp); template<> real modf(real const &x, real *iptr); template<> real ulp(real const &x); template<> real nextafter(real const &x, real const &y); -template<> real re(real const &x); +template<> real inverse(real const &x); template<> real sqrt(real const &x); template<> real cbrt(real const &x); template<> real pow(real const &x, real const &y); diff --git a/src/lol/math/transform.h b/src/lol/math/transform.h index 5fc7bb2a..debfb43d 100644 --- a/src/lol/math/transform.h +++ b/src/lol/math/transform.h @@ -400,7 +400,7 @@ static inline quat_t normalize(quat_t const &z) */ template -static inline cmplx_t re(cmplx_t const &z) +static inline cmplx_t inverse(cmplx_t const &z) { return ~z / sqlength(z); } @@ -408,13 +408,13 @@ static inline cmplx_t re(cmplx_t const &z) template static inline cmplx_t operator /(T a, cmplx_t const &b) { - return a * re(b); + return a * inverse(b); } template static inline cmplx_t operator /(cmplx_t a, cmplx_t const &b) { - return a * re(b); + return a * inverse(b); } template @@ -440,7 +440,7 @@ static inline bool operator !=(T a, cmplx_t const &b) { return b != a; } */ template -static inline quat_t re(quat_t const &q) +static inline quat_t inverse(quat_t const &q) { return ~q / sqlength(q); } @@ -448,13 +448,13 @@ static inline quat_t re(quat_t const &q) template static inline quat_t operator /(T x, quat_t const &y) { - return x * re(y); + return x * inverse(y); } template static inline quat_t operator /(quat_t const &x, quat_t const &y) { - return x * re(y); + return x * inverse(y); } template @@ -468,7 +468,7 @@ template static inline sqt_t inverse(sqt_t const &tr) { auto inv_s = T(1) / tr.s; - auto inv_q = re(tr.q); + auto inv_q = inverse(tr.q); return sqt_t(inv_s, inv_q, inv_q * tr.t * -inv_s); } diff --git a/src/math/real.cpp b/src/math/real.cpp index 6ecd4f0f..76c3c33b 100644 --- a/src/math/real.cpp +++ b/src/math/real.cpp @@ -25,7 +25,7 @@ namespace lol * done on demand, but here is the dependency list anyway: * - fast_log() requires R_1 * - log() requires R_LN2 - * - re() require R_2 + * - inverse() require R_2 * - exp() requires R_0, R_1, R_LN2 * - sqrt() requires R_3 */ @@ -48,16 +48,16 @@ LOL_CONSTANT_GETTER(R_10, (real)10.0); LOL_CONSTANT_GETTER(R_LN2, fast_log(R_2())); LOL_CONSTANT_GETTER(R_LN10, log(R_10())); -LOL_CONSTANT_GETTER(R_LOG2E, re(R_LN2())); -LOL_CONSTANT_GETTER(R_LOG10E, re(R_LN10())); +LOL_CONSTANT_GETTER(R_LOG2E, inverse(R_LN2())); +LOL_CONSTANT_GETTER(R_LOG10E, inverse(R_LN10())); LOL_CONSTANT_GETTER(R_E, exp(R_1())); LOL_CONSTANT_GETTER(R_PI, fast_pi()); LOL_CONSTANT_GETTER(R_PI_2, R_PI() / 2); LOL_CONSTANT_GETTER(R_PI_3, R_PI() / R_3()); LOL_CONSTANT_GETTER(R_PI_4, R_PI() / 4); -LOL_CONSTANT_GETTER(R_1_PI, re(R_PI())); +LOL_CONSTANT_GETTER(R_1_PI, inverse(R_PI())); LOL_CONSTANT_GETTER(R_2_PI, R_1_PI() * 2); -LOL_CONSTANT_GETTER(R_2_SQRTPI, re(sqrt(R_PI())) * 2); +LOL_CONSTANT_GETTER(R_2_SQRTPI, inverse(sqrt(R_PI())) * 2); LOL_CONSTANT_GETTER(R_SQRT2, sqrt(R_2())); LOL_CONSTANT_GETTER(R_SQRT3, sqrt(R_3())); LOL_CONSTANT_GETTER(R_SQRT1_2, R_SQRT2() / 2); @@ -487,7 +487,7 @@ template<> real real::operator *(real const &x) const template<> real real::operator /(real const &x) const { - return *this * re(x); + return *this * inverse(x); } template<> real const &real::operator +=(real const &x) @@ -608,7 +608,7 @@ template<> real clamp(real const &x, real const &a, real const &b) return (x < a) ? a : (x > b) ? b : x; } -template<> real re(real const &x) +template<> real inverse(real const &x) { if (!(x.m_signexp << 1)) { @@ -718,7 +718,7 @@ template<> real cbrt(real const &x) * convergence, but this hasn't been checked seriously. */ for (int i = 1; i <= real::BIGITS; i *= 2) { - static real third = re(real::R_3()); + static real third = inverse(real::R_3()); ret = third * (x / (ret * ret) + (ret / 2)); } @@ -1311,7 +1311,7 @@ template<> real atan(real const &x) } else { - real y = re(absx); + real y = inverse(absx); real yn = y, my2 = -y * y; ret = y; for (int i = 3; ; i += 2) diff --git a/src/t/math/cmplx.cpp b/src/t/math/cmplx.cpp index a76e5059..632c4044 100644 --- a/src/t/math/cmplx.cpp +++ b/src/t/math/cmplx.cpp @@ -88,10 +88,10 @@ lolunit_declare_fixture(complex_test) lolunit_assert_doubles_equal(norm(b), 1.0, 1e-8); } - lolunit_declare_test(reciprocal) + lolunit_declare_test(complex_inverse) { cmplx a(3.0f, -4.0f); - cmplx b = re(a); + cmplx b = inverse(a); lolunit_assert_equal(a * b, b * a); diff --git a/src/t/math/quat.cpp b/src/t/math/quat.cpp index 34999d69..e005095a 100644 --- a/src/t/math/quat.cpp +++ b/src/t/math/quat.cpp @@ -140,10 +140,10 @@ lolunit_declare_fixture(quaternion_test) lolunit_assert_doubles_equal(norm(b), 1.0, 1e-5); } - lolunit_declare_test(reciprocal) + lolunit_declare_test(quaternion_inverse) { quat a(2.f, -2.f, -8.f, 3.f); - quat b = re(a); + quat b = inverse(a); quat c = 1.f / a; lolunit_assert_doubles_equal(b.w, c.w, 1e-5); diff --git a/src/t/math/real.cpp b/src/t/math/real.cpp index fe2929f3..404f613e 100644 --- a/src/t/math/real.cpp +++ b/src/t/math/real.cpp @@ -38,12 +38,12 @@ lolunit_declare_fixture(real_test) lolunit_assert_equal(b1, 1.0); lolunit_assert_equal(b2, 1.0); - double c1 = exp(re(real::R_LOG2E())); + double c1 = exp(inverse(real::R_LOG2E())); double c2 = log(exp2(real::R_LOG2E())); lolunit_assert_equal(c1, 2.0); lolunit_assert_equal(c2, 1.0); - double d1 = exp(re(real::R_LOG10E())); + double d1 = exp(inverse(real::R_LOG10E())); lolunit_assert_equal(d1, 10.0); double e1 = exp(real::R_LN2());