From 1417a8acd21c80ac852bfd86dc160534c272ecd2 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Fri, 4 May 2012 18:21:18 +0900 Subject: [PATCH] add sprout::exp2, expm1 --- sprout/math/exp10.hpp | 38 +++++++++++++++++++++++++++++++ sprout/math/exp2.hpp | 45 +++++++++++++++++++++++++++++++++++++ sprout/math/expm1.hpp | 45 +++++++++++++++++++++++++++++++++++++ sprout/math/exponential.hpp | 3 +++ 4 files changed, 131 insertions(+) create mode 100644 sprout/math/exp10.hpp create mode 100644 sprout/math/exp2.hpp create mode 100644 sprout/math/expm1.hpp diff --git a/sprout/math/exp10.hpp b/sprout/math/exp10.hpp new file mode 100644 index 00000000..350014a8 --- /dev/null +++ b/sprout/math/exp10.hpp @@ -0,0 +1,38 @@ +#ifndef SPROUT_MATH_EXP10_HPP +#define SPROUT_MATH_EXP10_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR FloatType + exp10(FloatType x) { + return sprout::math::detail::exp(x * sprout::math::ln_ten()); + } + + template< + typename IntType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR double + exp10(IntType x) { + return sprout::math::detail::exp10(static_cast(x)); + } + } // namespace detail + + using sprout::math::detail::exp10; + } // namespace math + + using sprout::math::exp10; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_EXP10_HPP diff --git a/sprout/math/exp2.hpp b/sprout/math/exp2.hpp new file mode 100644 index 00000000..f2c3f4b2 --- /dev/null +++ b/sprout/math/exp2.hpp @@ -0,0 +1,45 @@ +#ifndef SPROUT_MATH_EXP2_HPP +#define SPROUT_MATH_EXP2_HPP + +#include +#include +#include +#include +#include +#if SPROUT_USE_BUILTIN_CMATH_FUNCTION +# include +#endif + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR FloatType + exp2(FloatType x) { + return sprout::math::detail::exp(x * sprout::math::ln_two()); + } + + template< + typename IntType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR double + exp2(IntType x) { + return sprout::math::detail::exp2(static_cast(x)); + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::exp2; +# else + using sprout::math::detail::exp2; +# endif + } // namespace math + + using sprout::math::exp2; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_EXP2_HPP diff --git a/sprout/math/expm1.hpp b/sprout/math/expm1.hpp new file mode 100644 index 00000000..078c392a --- /dev/null +++ b/sprout/math/expm1.hpp @@ -0,0 +1,45 @@ +#ifndef SPROUT_MATH_EXPM1_HPP +#define SPROUT_MATH_EXPM1_HPP + +#include +#include +#include +#include +#include +#if SPROUT_USE_BUILTIN_CMATH_FUNCTION +# include +#endif + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR FloatType + expm1(FloatType x) { + return sprout::math::detail::exp(x) - 1; + } + + template< + typename IntType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR double + expm1(IntType x) { + return sprout::math::detail::expm1(static_cast(x)); + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::expm1; +# else + using sprout::math::detail::expm1; +# endif + } // namespace math + + using sprout::math::expm1; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_EXPM1_HPP diff --git a/sprout/math/exponential.hpp b/sprout/math/exponential.hpp index 9cd437de..fc686146 100644 --- a/sprout/math/exponential.hpp +++ b/sprout/math/exponential.hpp @@ -2,6 +2,9 @@ #define SPROUT_MATH_EXPONENTIAL_HPP #include +#include +#include +#include #include #include #include