Przeglądaj źródła

math: rename re() to inverse() in all classes.

The name “re” came from “reciprocal” but since we have “inverse” for
matrices, I thought it would be nice to make everything consistent.
undefined
Sam Hocevar 9 lat temu
rodzic
commit
45b57cc102
6 zmienionych plików z 25 dodań i 25 usunięć
  1. +3
    -3
      src/lol/math/real.h
  2. +7
    -7
      src/lol/math/transform.h
  3. +9
    -9
      src/math/real.cpp
  4. +2
    -2
      src/t/math/cmplx.cpp
  5. +2
    -2
      src/t/math/quat.cpp
  6. +2
    -2
      src/t/math/real.cpp

+ 3
- 3
src/lol/math/real.h Wyświetl plik

@@ -111,7 +111,7 @@ public:
template<int K> friend Real<K> nextafter(Real<K> const &x, Real<K> const &y);

/* Power functions */
template<int K> friend Real<K> re(Real<K> const &x);
template<int K> friend Real<K> inverse(Real<K> const &x);
template<int K> friend Real<K> sqrt(Real<K> const &x);
template<int K> friend Real<K> cbrt(Real<K> const &x);
template<int K> friend Real<K> pow(Real<K> const &x, Real<K> const &y);
@@ -270,7 +270,7 @@ template<int K> Real<K> ldexp(Real<K> const &x, int exp);
template<int K> Real<K> modf(Real<K> const &x, Real<K> *iptr);
template<int K> Real<K> ulp(Real<K> const &x);
template<int K> Real<K> nextafter(Real<K> const &x, Real<K> const &y);
template<int K> Real<K> re(Real<K> const &x);
template<int K> Real<K> inverse(Real<K> const &x);
template<int K> Real<K> sqrt(Real<K> const &x);
template<int K> Real<K> cbrt(Real<K> const &x);
template<int K> Real<K> pow(Real<K> const &x, Real<K> 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);


+ 7
- 7
src/lol/math/transform.h Wyświetl plik

@@ -400,7 +400,7 @@ static inline quat_t<T> normalize(quat_t<T> const &z)
*/

template<typename T>
static inline cmplx_t<T> re(cmplx_t<T> const &z)
static inline cmplx_t<T> inverse(cmplx_t<T> const &z)
{
return ~z / sqlength(z);
}
@@ -408,13 +408,13 @@ static inline cmplx_t<T> re(cmplx_t<T> const &z)
template<typename T>
static inline cmplx_t<T> operator /(T a, cmplx_t<T> const &b)
{
return a * re(b);
return a * inverse(b);
}

template<typename T>
static inline cmplx_t<T> operator /(cmplx_t<T> a, cmplx_t<T> const &b)
{
return a * re(b);
return a * inverse(b);
}

template<typename T>
@@ -440,7 +440,7 @@ static inline bool operator !=(T a, cmplx_t<T> const &b) { return b != a; }
*/

template<typename T>
static inline quat_t<T> re(quat_t<T> const &q)
static inline quat_t<T> inverse(quat_t<T> const &q)
{
return ~q / sqlength(q);
}
@@ -448,13 +448,13 @@ static inline quat_t<T> re(quat_t<T> const &q)
template<typename T>
static inline quat_t<T> operator /(T x, quat_t<T> const &y)
{
return x * re(y);
return x * inverse(y);
}

template<typename T>
static inline quat_t<T> operator /(quat_t<T> const &x, quat_t<T> const &y)
{
return x * re(y);
return x * inverse(y);
}

template<typename T>
@@ -468,7 +468,7 @@ template<typename T>
static inline sqt_t<T> inverse(sqt_t<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<T>(inv_s, inv_q, inv_q * tr.t * -inv_s);
}



+ 9
- 9
src/math/real.cpp Wyświetl plik

@@ -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)


+ 2
- 2
src/t/math/cmplx.cpp Wyświetl plik

@@ -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);



+ 2
- 2
src/t/math/quat.cpp Wyświetl plik

@@ -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);


+ 2
- 2
src/t/math/real.cpp Wyświetl plik

@@ -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());


Ładowanie…
Anuluj
Zapisz