|
// Copyright: Andreas Raczek
// This file is published under the The Code Project Open License (CPOL)
// See the file "CPOL.html" for the full license governing this code.
#pragma once
namespace lobster {
namespace tmp {
#pragma region power implementation for unsigned exponents
template<
long base,
unsigned long exp
> struct power_enum {
enum {
value = base * power_enum<base, exp - 1>::value
};
};
template<long base>
struct power_enum<
base,
0
> {
enum {
value = 1
};
};
#pragma endregion
#pragma region power implementation for signed exponents
template<
long base,
unsigned long exp,
bool negative>
struct power_double_helper {
const static double value;
};
template<long base, unsigned long exp, bool negative>
const double power_double_helper<base, exp, negative>::value = (double) power_enum<base, exp>::value;
template<
long base,
unsigned long exp>
struct power_double_helper<
base,
exp,
true
> {
const static double value;
};
template<long base, unsigned long exp>
const double power_double_helper<base, exp, true>::value = 1.0 / (double) power_enum<base, exp>::value;
template<long base, long exp>
struct power_double {
const static double value;
};
template<long base, long exp>
const double power_double<base, exp>::value =
power_double_helper<
base,
exp >= 0 ? exp : -exp,
exp < 0
>::value;
#pragma endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.