From 8dadcb359a3849682f42ea4cc807dbfc7ab911ea Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 5 May 2012 00:24:10 +0900 Subject: [PATCH] add sprout::asinh, acosh, atanh --- sprout/math/acosh.hpp | 48 +++++++++++++++++++++++++++++++++++++ sprout/math/asinh.hpp | 46 +++++++++++++++++++++++++++++++++++ sprout/math/atanh.hpp | 49 ++++++++++++++++++++++++++++++++++++++ sprout/math/hyperbolic.hpp | 3 +++ 4 files changed, 146 insertions(+) create mode 100644 sprout/math/acosh.hpp create mode 100644 sprout/math/asinh.hpp create mode 100644 sprout/math/atanh.hpp diff --git a/sprout/math/acosh.hpp b/sprout/math/acosh.hpp new file mode 100644 index 00000000..d8a750a9 --- /dev/null +++ b/sprout/math/acosh.hpp @@ -0,0 +1,48 @@ +#ifndef SPROUT_MATH_ACOSH_HPP +#define SPROUT_MATH_ACOSH_HPP + +#include +#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 + acosh(FloatType x) { + return x < 1 ? std::numeric_limits::quiet_NaN() + : sprout::math::detail::log(x + sprout::math::detail::sqrt(x * x - 1)) + ; + } + + template< + typename IntType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR double + acosh(IntType x) { + return sprout::math::detail::acosh(static_cast(x)); + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::acosh; +# else + using sprout::math::detail::acosh; +# endif + } // namespace math + + using sprout::math::acosh; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_ACOSH_HPP diff --git a/sprout/math/asinh.hpp b/sprout/math/asinh.hpp new file mode 100644 index 00000000..ef0fc6bd --- /dev/null +++ b/sprout/math/asinh.hpp @@ -0,0 +1,46 @@ +#ifndef SPROUT_MATH_ASINH_HPP +#define SPROUT_MATH_ASINH_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 + asinh(FloatType x) { + return sprout::math::detail::log(x + sprout::math::detail::sqrt(x * x + 1)) + ; + } + + template< + typename IntType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR double + asinh(IntType x) { + return sprout::math::detail::asinh(static_cast(x)); + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::asinh; +# else + using sprout::math::detail::asinh; +# endif + } // namespace math + + using sprout::math::asinh; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_ASINH_HPP diff --git a/sprout/math/atanh.hpp b/sprout/math/atanh.hpp new file mode 100644 index 00000000..1cc722fc --- /dev/null +++ b/sprout/math/atanh.hpp @@ -0,0 +1,49 @@ +#ifndef SPROUT_MATH_ATANH_HPP +#define SPROUT_MATH_ATANH_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 + atanh(FloatType x) { + return x < -1 || x > 1 ? std::numeric_limits::quiet_NaN() + : x == -1 ? -std::numeric_limits::infinity() + : x == 1 ? std::numeric_limits::infinity() + : sprout::math::detail::log((1 + x) / (1 - x)) / 2 + ; + } + + template< + typename IntType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR double + atanh(IntType x) { + return sprout::math::detail::atanh(static_cast(x)); + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::atanh; +# else + using sprout::math::detail::atanh; +# endif + } // namespace math + + using sprout::math::atanh; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_ATANH_HPP diff --git a/sprout/math/hyperbolic.hpp b/sprout/math/hyperbolic.hpp index 32ae4216..731ea42e 100644 --- a/sprout/math/hyperbolic.hpp +++ b/sprout/math/hyperbolic.hpp @@ -4,5 +4,8 @@ #include #include #include +#include +#include +#include #endif // #ifndef SPROUT_MATH_HYPERBOLIC_HPP