maths: remove pow2 function

pow2 has been used enough times to mean 2^x and x^2 that it's not worth
the ambiguity. just use pow(b,e) directly.
This commit is contained in:
Danny Robson 2018-04-09 12:30:22 +10:00
parent d1da97f213
commit 24a530e23e
6 changed files with 14 additions and 19 deletions

View File

@ -30,10 +30,10 @@ namespace util {
CHECK_GE (t, 0.f);
CHECK_LE (t, 1.f);
auto v0 = pow (1 - t, 3u) * m_points[0];
auto v1 = 3 * pow2 (1 - t) * t * m_points[1];
auto v2 = 3 * pow2 (1 - t) * t * m_points[2];
auto v3 = pow (t, 3u) * m_points[3];
auto v0 = pow (1 - t, 3u) * m_points[0];
auto v1 = 3 * pow (1 - t, 2u) * t * m_points[1];
auto v2 = 3 * pow (1 - t, 2u) * t * m_points[2];
auto v3 = pow (t, 3u) * m_points[3];
return {
v0.x + v1.x + v2.x + v3.x,

View File

@ -207,16 +207,6 @@ namespace util {
///////////////////////////////////////////////////////////////////////////
// exponentials
template <typename T>
constexpr T
pow2 [[gnu::const]] (T value)
{
return value * value;
}
///////////////////////////////////////////////////////////////////////////
template <
typename BaseT,
typename ExponentT,
@ -229,7 +219,12 @@ namespace util {
pow [[gnu::const]] (BaseT base, ExponentT exponent)
{
assert (exponent >= 0);
return exponent == 0 ? BaseT{1} : base * pow (base, exponent - 1);
if (exponent == 1)
return base;
if (exponent == 0)
return BaseT{1};
return base * pow (base, exponent - 1);
}

View File

@ -112,7 +112,7 @@ namespace util {
constexpr typename std::common_type<T,U>::type
distance2 (point<S,T> a, point<S,U> b)
{
return sum (pow2 (a - b));
return sum (pow (a - b, 2));
}
/// computes the octile distance between two points. that is, the shortest

View File

@ -57,7 +57,7 @@ namespace util::polynomial {
return { s[0], std::numeric_limits<float>::quiet_NaN () };
}
auto descriminator = std::sqrt (pow2 (b) - 4 * a * c);
auto descriminator = std::sqrt (pow (b,2) - 4 * a * c);
return {
(-b - descriminator) / (2 * a),
(-b + descriminator) / (2 * a)

View File

@ -87,5 +87,5 @@ lcg<T,M,A,C>::discard (unsigned count)
///////////////////////////////////////////////////////////////////////////////
template struct util::rand::lcg<uint32_t, util::pow2(31), 1103515245, 12345>;
template struct util::rand::lcg<uint32_t, util::pow(31,2), 1103515245, 12345>;
template struct util::rand::lcg<uint64_t, 0ul, 6364136223846793005ul, 1ul>;

View File

@ -166,7 +166,7 @@ main (void)
tap.expect_eq (util::digits10( 1), 1, "digits10, 1");
tap.expect_eq (util::digits10(10), 2, "digits10, 10");
tap.expect_eq (util::pow2 (4u), 16u, "pow2");
tap.expect_eq (util::pow (4u,2), 16u, "pow2");
static const float POS_ZERO = 1.f / numeric_limits<float>::infinity ();