mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
Math: integer power function
This commit is contained in:
parent
086c49237d
commit
2af61252b6
38
lib/Math.hpp
38
lib/Math.hpp
@ -26,6 +26,38 @@
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Custom math functions *
|
||||
******************************************************************************/
|
||||
#define MATH_NAMESPACE Math
|
||||
|
||||
namespace MATH_NAMESPACE
|
||||
{
|
||||
// integer power function
|
||||
template <unsigned int n, typename T>
|
||||
typename std::enable_if<(n == 0), T>::type pow(const T x __unused)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <unsigned int n, typename T>
|
||||
typename std::enable_if<(n == 1), T>::type pow(const T x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
template <unsigned int n, typename T>
|
||||
typename std::enable_if<(n > 1), T>::type pow(const T x)
|
||||
{
|
||||
return x*pow<n-1>(x);
|
||||
}
|
||||
|
||||
// Constants
|
||||
const double pi = 3.1415926535897932384626433832795028841970;
|
||||
const double e = 2.7182818284590452353602874713526624977572;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Standard C functions *
|
||||
******************************************************************************/
|
||||
@ -93,12 +125,6 @@ DECL_STD_FUNC(fmin)
|
||||
// Absolute value
|
||||
DECL_STD_FUNC(fabs)
|
||||
|
||||
namespace STDMATH_NAMESPACE
|
||||
{
|
||||
// Constants
|
||||
const double pi = 3.1415926535897932384626433832795028841970;
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
|
||||
#endif // Latan_Math_hpp_
|
||||
|
Loading…
Reference in New Issue
Block a user