1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

add math::copysign

fix hyperbolic and exponental functions: for special values
This commit is contained in:
bolero-MURAKAMI 2013-04-24 22:48:36 +09:00
parent a27c83e939
commit 32c3ba02d4
50 changed files with 540 additions and 216 deletions

View file

@ -5,26 +5,37 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/log.hpp>
#include <sprout/math/sqrt.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
acosh_impl(T x) {
return sprout::math::log(x + sprout::math::sqrt(x * x - 1));
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
acosh(FloatType x) {
return x == 1 ? FloatType(0)
: x < 1 ? std::numeric_limits<FloatType>::quiet_NaN()
return x < 1 ? std::numeric_limits<FloatType>::quiet_NaN()
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: sprout::log(x + sprout::sqrt(x * x - 1))
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::acosh(x)
#else
: x == 1 ? FloatType(0)
: static_cast<FloatType>(sprout::math::detail::acosh_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -34,8 +45,17 @@ namespace sprout {
return sprout::math::detail::acosh(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::acosh;
//
// acosh
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
acosh(ArithmeticType x) {
return sprout::math::detail::acosh(x);
}
} // namespace math
using sprout::math::acosh;

View file

@ -10,6 +10,7 @@
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/math/factorial.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/fabs.hpp>
#include <sprout/math/sqrt.hpp>
#include <sprout/type_traits/enabler_if.hpp>
@ -48,7 +49,7 @@ namespace sprout {
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::asin(x)
#else
: x == 0 ? FloatType(0)
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(
x < 0 ? -sprout::math::detail::asin_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(-x))
: sprout::math::detail::asin_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x))

View file

@ -5,26 +5,38 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/log.hpp>
#include <sprout/math/sqrt.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
asinh_impl(T x) {
return sprout::math::log(x + sprout::math::sqrt(x * x + 1));
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
asinh(FloatType x) {
return x == 0 ? FloatType(0)
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
return x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
: sprout::log(x + sprout::sqrt(x * x + 1))
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::asinh(x)
#else
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(sprout::math::detail::asinh_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -34,8 +46,17 @@ namespace sprout {
return sprout::math::detail::asinh(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::asinh;
//
// asinh
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
asinh(ArithmeticType x) {
return sprout::math::detail::asinh(x);
}
} // namespace math
using sprout::math::asinh;

View file

@ -10,6 +10,7 @@
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/math/factorial.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
@ -42,12 +43,12 @@ namespace sprout {
>
inline SPROUT_CONSTEXPR FloatType
atan(FloatType x) {
return x == 0 ? FloatType(0)
: x == std::numeric_limits<FloatType>::infinity() ? sprout::math::half_pi<FloatType>()
return x == std::numeric_limits<FloatType>::infinity() ? sprout::math::half_pi<FloatType>()
: x == -std::numeric_limits<FloatType>::infinity() ? -sprout::math::half_pi<FloatType>()
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::atan(x)
#else
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(
x < 0 ? -sprout::math::detail::atan_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(-x))
: sprout::math::detail::atan_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x))

View file

@ -7,8 +7,9 @@
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/signbit.hpp>
#include <sprout/math/atan.hpp>
#include <sprout/type_traits/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
@ -35,20 +36,21 @@ namespace sprout {
return x == -std::numeric_limits<FloatType>::infinity()
? y == std::numeric_limits<FloatType>::infinity() ? sprout::math::three_quarters_pi<FloatType>()
: y == -std::numeric_limits<FloatType>::infinity() ? -sprout::math::three_quarters_pi<FloatType>()
: y < 0 ? -sprout::math::half_pi<FloatType>()
: sprout::math::half_pi<FloatType>()
: sprout::math::copysign(sprout::math::pi<FloatType>(), y)
: x == std::numeric_limits<FloatType>::infinity()
? y == std::numeric_limits<FloatType>::infinity() ? sprout::math::quarter_pi<FloatType>()
: y == -std::numeric_limits<FloatType>::infinity() ? -sprout::math::quarter_pi<FloatType>()
: FloatType(0)
: sprout::math::copysign(FloatType(0), y)
: y == std::numeric_limits<FloatType>::infinity() ? sprout::math::half_pi<FloatType>()
: y == -std::numeric_limits<FloatType>::infinity() ? -sprout::math::half_pi<FloatType>()
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::atan2(y, x)
#else
: y == 0
? x < 0 ? sprout::math::pi<FloatType>()
: FloatType(0)
? x < 0 ? sprout::math::copysign(sprout::math::pi<FloatType>(), y)
: x > 0 ? sprout::math::copysign(FloatType(0), y)
: sprout::math::signbit(x) ? sprout::math::copysign(sprout::math::pi<FloatType>(), y)
: sprout::math::copysign(FloatType(0), y)
: x == 0
? y < 0 ? -sprout::math::half_pi<FloatType>()
: sprout::math::half_pi<FloatType>()

View file

@ -5,26 +5,39 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/log.hpp>
#include <sprout/math/fabs.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
atanh_impl(T x) {
return sprout::math::log((1 + x) / (1 - x)) / 2;
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
atanh(FloatType x) {
return x == 0 ? FloatType(0)
: x == 1 ? std::numeric_limits<FloatType>::infinity()
return x == 1 ? std::numeric_limits<FloatType>::infinity()
: x == -1 ? -std::numeric_limits<FloatType>::infinity()
: x > 1 || x < -1 ? std::numeric_limits<FloatType>::quiet_NaN()
: sprout::log((1 + x) / (1 - x)) / 2
: sprout::math::fabs(x) > 1 ? std::numeric_limits<FloatType>::quiet_NaN()
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::atanh(x)
#else
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(sprout::math::detail::atanh_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -34,8 +47,17 @@ namespace sprout {
return sprout::math::detail::atanh(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::atanh;
//
// atanh
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
atanh(ArithmeticType x) {
return sprout::math::detail::atanh(x);
}
} // namespace math
using sprout::math::atanh;

View file

@ -11,6 +11,7 @@
#include <sprout/math/gamma.hpp>
#include <sprout/math/nearest.hpp>
#include <sprout/math/remainders.hpp>
#include <sprout/math/manipulations.hpp>
#include <sprout/math/minmax.hpp>
#include <sprout/math/muladd.hpp>

44
sprout/math/copysign.hpp Normal file
View file

@ -0,0 +1,44 @@
#ifndef SPROUT_MATH_COPYSIGN_HPP
#define SPROUT_MATH_COPYSIGN_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/signbit.hpp>
#include <sprout/type_traits/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
namespace math {
namespace detail {
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
copysign(FloatType x, FloatType y) {
return sprout::math::signbit(y) != sprout::math::signbit(x) ? -x
: x
;
}
template<
typename ArithmeticType1,
typename ArithmeticType2,
typename sprout::enabler_if<
std::is_arithmetic<ArithmeticType1>::value && std::is_arithmetic<ArithmeticType2>::value
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type
copysign(ArithmeticType1 x, ArithmeticType2 y) {
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
return sprout::math::detail::copysign(static_cast<type>(x), static_cast<type>(y));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::copysign;
} // namespace math
using sprout::math::copysign;
} // namespace sprout
#endif // #ifndef SPROUT_MATH_COPYSIGN_HPP

View file

@ -21,7 +21,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR T
cos_impl_1(T x2, std::size_t n, std::size_t last) {
return last - n == 1
? (n % 2 ? -1 : 1) * sprout::detail::pow_n(x2, n) / sprout::math::factorial<T>(2 * n)
? (n % 2 ? -1 : 1) * sprout::detail::pow_n(x2, n) / sprout::math::unchecked_factorial<T>(2 * n)
: sprout::math::detail::cos_impl_1(x2, n, n + (last - n) / 2)
+ sprout::math::detail::cos_impl_1(x2, n + (last - n) / 2, last)
;

View file

@ -10,19 +10,28 @@
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/factorial.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
cosh_impl(T x2, std::size_t n, std::size_t last) {
cosh_impl_1(T x2, std::size_t n, std::size_t last) {
return last - n == 1
? sprout::detail::pow_n(x2, n) / sprout::math::factorial<T>(2 * n)
: sprout::math::detail::cosh_impl(x2, n, n + (last - n) / 2)
+ sprout::math::detail::cosh_impl(x2, n + (last - n) / 2, last)
? sprout::detail::pow_n(x2, n) / sprout::math::unchecked_factorial<T>(2 * n)
: sprout::math::detail::cosh_impl_1(x2, n, n + (last - n) / 2)
+ sprout::math::detail::cosh_impl_1(x2, n + (last - n) / 2, last)
;
}
template<typename T>
inline SPROUT_CONSTEXPR T
cosh_impl(T x) {
return T(1) + sprout::math::detail::cosh_impl_1(
x * x,
1, sprout::math::factorial_limit<T>() / 2 + 1
);
}
template<
typename FloatType,
@ -30,19 +39,17 @@ namespace sprout {
>
inline SPROUT_CONSTEXPR FloatType
cosh(FloatType x) {
typedef typename sprout::math::detail::float_compute<FloatType>::type type;
return x == 0 ? FloatType(1)
: x == std::numeric_limits<FloatType>::infinity() || x == -std::numeric_limits<FloatType>::infinity()
return x == std::numeric_limits<FloatType>::infinity()
|| x == -std::numeric_limits<FloatType>::infinity()
? std::numeric_limits<FloatType>::infinity()
: static_cast<FloatType>(
type(1) + sprout::math::detail::cosh_impl(
static_cast<type>(x) * static_cast<type>(x),
1, sprout::math::factorial_limit<type>() / 2 + 1
)
)
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::cosh(x)
#else
: x == 0 ? FloatType(1)
: static_cast<FloatType>(sprout::math::detail::cosh_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -52,8 +59,17 @@ namespace sprout {
return sprout::math::detail::cosh(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::cosh;
//
// cosh
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
cosh(ArithmeticType x) {
return sprout::math::detail::cosh(x);
}
} // namespace math
using sprout::math::cosh;

View file

@ -10,6 +10,7 @@
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/factorial.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
@ -18,7 +19,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR T
exp_impl_1(T x, std::size_t n, std::size_t last) {
return last - n == 1
? sprout::detail::pow_n(x, n) / sprout::math::factorial<T>(n)
? sprout::detail::pow_n(x, n) / sprout::math::unchecked_factorial<T>(n)
: sprout::math::detail::exp_impl_1(x, n, n + (last - n) / 2)
+ sprout::math::detail::exp_impl_1(x, n + (last - n) / 2, last)
;
@ -26,7 +27,9 @@ namespace sprout {
template<typename T>
inline SPROUT_CONSTEXPR T
exp_impl(T x) {
return T(1) + sprout::math::detail::exp_impl_1(x, 1, sprout::math::factorial_limit<T>() / 2 + 1);
return !(x > -1) ? T(1) / (T(1) + sprout::math::detail::exp_impl_1(-x, 1, sprout::math::factorial_limit<T>() / 2 + 1))
: T(1) + sprout::math::detail::exp_impl_1(x, 1, sprout::math::factorial_limit<T>() / 2 + 1)
;
}
template<
@ -35,15 +38,16 @@ namespace sprout {
>
inline SPROUT_CONSTEXPR FloatType
exp(FloatType x) {
typedef typename sprout::math::detail::float_compute<FloatType>::type type;
return x == 0 ? FloatType(1)
: x == -std::numeric_limits<FloatType>::infinity() ? FloatType(0)
return x == -std::numeric_limits<FloatType>::infinity() ? FloatType(0)
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: !(x > -1) ? static_cast<FloatType>(type(1) / sprout::math::detail::exp_impl(-static_cast<type>(x)))
: static_cast<FloatType>(sprout::math::detail::exp_impl(static_cast<type>(x)))
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::exp(x)
#else
: x == 0 ? FloatType(1)
: static_cast<FloatType>(sprout::math::detail::exp_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -53,8 +57,17 @@ namespace sprout {
return sprout::math::detail::exp(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::exp;
//
// exp
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
exp(ArithmeticType x) {
return sprout::math::detail::exp(x);
}
} // namespace math
using sprout::math::exp;

View file

@ -4,26 +4,34 @@
#include <limits>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/exp.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
exp10_impl(T x) {
return sprout::math::exp(x * sprout::math::ln_ten<T>());
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
exp10(FloatType x) {
return x == 0 ? FloatType(1)
: x == -std::numeric_limits<FloatType>::infinity() ? FloatType(0)
return x == -std::numeric_limits<FloatType>::infinity() ? FloatType(0)
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: sprout::exp(x * sprout::math::ln_ten<FloatType>())
: x == 0 ? FloatType(1)
: static_cast<FloatType>(sprout::math::detail::exp10_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -33,8 +41,17 @@ namespace sprout {
return sprout::math::detail::exp10(static_cast<double>(x));
}
} // namespace detail
using sprout::math::detail::exp10;
//
// exp10
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
exp10(ArithmeticType x) {
return sprout::math::detail::exp10(x);
}
} // namespace math
using sprout::math::exp10;

View file

@ -5,26 +5,37 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/exp.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
exp2_impl(T x) {
return sprout::math::exp(x * sprout::math::ln_two<T>());
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
exp2(FloatType x) {
return x == 0 ? FloatType(1)
: x == -std::numeric_limits<FloatType>::infinity() ? FloatType(0)
return x == -std::numeric_limits<FloatType>::infinity() ? FloatType(0)
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: sprout::exp(x * sprout::math::ln_two<FloatType>())
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::exp2(x)
#else
: x == 0 ? FloatType(1)
: static_cast<FloatType>(sprout::math::detail::exp2_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -34,8 +45,17 @@ namespace sprout {
return sprout::math::detail::exp2(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::exp2;
//
// exp2
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
exp2(ArithmeticType x) {
return sprout::math::detail::exp2(x);
}
} // namespace math
using sprout::math::exp2;

View file

@ -5,26 +5,38 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/exp.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
expm1_impl(T x) {
return sprout::math::exp(x) - T(1);
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
expm1(FloatType x) {
return x == 0 ? FloatType(0)
: x == -std::numeric_limits<FloatType>::infinity() ? FloatType(-1)
return x == -std::numeric_limits<FloatType>::infinity() ? FloatType(-1)
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: sprout::exp(x) - FloatType(1)
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::expm1(x)
#else
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(sprout::math::detail::expm1_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -34,8 +46,17 @@ namespace sprout {
return sprout::math::detail::expm1(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::expm1;
//
// expm1
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
expm1(ArithmeticType x) {
return sprout::math::detail::expm1(x);
}
} // namespace math
using sprout::math::expm1;

View file

@ -4,6 +4,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
@ -15,9 +16,8 @@ namespace sprout {
>
inline SPROUT_CONSTEXPR FloatType
fabs(FloatType x) {
return x < 0 ? -x : x;
return sprout::math::copysign(x, FloatType(0));
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler

View file

@ -25,7 +25,7 @@ namespace sprout {
? std::numeric_limits<FloatType>::infinity()
: x == std::numeric_limits<FloatType>::infinity() || x == -std::numeric_limits<FloatType>::infinity()
? std::numeric_limits<FloatType>::infinity()
: sprout::sqrt(x * x + y * y)
: sprout::math::sqrt(x * x + y * y)
;
}

View file

@ -20,7 +20,7 @@ namespace sprout {
template<typename T>
inline SPROUT_CONSTEXPR T
lgamma_impl_3(T x, T y) {
return x < 0 ? sprout::log(sprout::math::pi<T>() / sprout::math::fabs(x * sprout::math::sin(x * sprout::math::pi<T>()))) - y
return x < 0 ? sprout::math::log(sprout::math::pi<T>() / sprout::math::fabs(x * sprout::math::sin(x * sprout::math::pi<T>()))) - y
: y
;
}
@ -31,7 +31,7 @@ namespace sprout {
x,
(((((-0.00163312359200500807 * t + 8.3644533703385956e-4) * t + -5.9518947575728181e-4) * t
+ 7.9365057505415415e-4) * t + -0.00277777777735463043) * t + 0.08333333333333309869) * v + 0.91893853320467274178
+ ((w - T(0.5)) * sprout::log(w) - w)
+ ((w - T(0.5)) * sprout::math::log(w) - w)
);
}
template<typename T>
@ -145,7 +145,7 @@ namespace sprout {
lgamma_impl_2_a(T x, T w, int k) {
return sprout::math::detail::lgamma_impl_3(
x,
-sprout::log(
-sprout::math::log(
k == 0 ? ((((((((((
9.967270908702825e-5 * w + -1.9831672170162227e-4) * w
+ -0.00117085315349625822) * w + 0.00722012810948319552) * w + -0.0096221300936780297) * w

View file

@ -12,25 +12,33 @@
#include <sprout/math/factorial.hpp>
#include <sprout/math/sqrt.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
log_impl_1(T x, std::size_t n, std::size_t last) {
log_impl_2(T x, std::size_t n, std::size_t last) {
return last - n == 1
? (n % 2 ? 1 : -1) * sprout::detail::pow_n(x, n) / n
: sprout::math::detail::log_impl_1(x, n, n + (last - n) / 2)
+ sprout::math::detail::log_impl_1(x, n + (last - n) / 2, last)
: sprout::math::detail::log_impl_2(x, n, n + (last - n) / 2)
+ sprout::math::detail::log_impl_2(x, n + (last - n) / 2, last)
;
}
template<typename T>
inline SPROUT_CONSTEXPR T
log_impl_1(T x) {
return !(x > sprout::math::root_two<T>())
? sprout::math::detail::log_impl_2(x - T(1), 1, sprout::math::factorial_limit<T>() + 1)
: T(2) * sprout::math::detail::log_impl_1(sprout::math::sqrt(x))
;
}
template<typename T>
inline SPROUT_CONSTEXPR T
log_impl(T x) {
return !(x > sprout::math::root_two<T>())
? sprout::math::detail::log_impl_1(x - 1, 1, sprout::math::factorial_limit<T>() + 1)
: 2 * sprout::math::detail::log_impl(sprout::sqrt(x))
return x < 1 ? -sprout::math::detail::log_impl_1(T(1) / x)
: sprout::math::detail::log_impl_1(x)
;
}
@ -40,16 +48,17 @@ namespace sprout {
>
inline SPROUT_CONSTEXPR FloatType
log(FloatType x) {
typedef typename sprout::math::detail::float_compute<FloatType>::type type;
return x == 0 ? -std::numeric_limits<FloatType>::infinity()
: x == 1 ? FloatType(0)
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: x < 0 ? std::numeric_limits<FloatType>::quiet_NaN()
: x < 1 ? static_cast<FloatType>(-sprout::math::detail::log_impl(1 / static_cast<type>(x)))
: static_cast<FloatType>(sprout::math::detail::log_impl(static_cast<type>(x)))
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::log(x)
#else
: x == 1 ? FloatType(0)
: static_cast<FloatType>(sprout::math::detail::log_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -59,8 +68,17 @@ namespace sprout {
return sprout::math::detail::log(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::log;
//
// log
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
log(ArithmeticType x) {
return sprout::math::detail::log(x);
}
} // namespace math
using sprout::math::log;

View file

@ -5,13 +5,21 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/log.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
log10_impl(T x) {
return sprout::math::log(x) / sprout::math::ln_ten<T>();
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
@ -19,13 +27,16 @@ namespace sprout {
inline SPROUT_CONSTEXPR FloatType
log10(FloatType x) {
return x == 0 ? -std::numeric_limits<FloatType>::infinity()
: x == 1 ? FloatType(0)
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: x < 0 ? std::numeric_limits<FloatType>::quiet_NaN()
: sprout::log(x) / sprout::math::ln_ten<FloatType>()
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::log10(x)
#else
: x == 1 ? FloatType(0)
: static_cast<FloatType>(sprout::math::detail::log10_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -35,8 +46,17 @@ namespace sprout {
return sprout::math::detail::log10(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::log10;
//
// log10
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
log10(ArithmeticType x) {
return sprout::math::detail::log10(x);
}
} // namespace math
using sprout::math::log10;

View file

@ -5,26 +5,38 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/log.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
log1p_impl(T x) {
return sprout::math::log(T(1) + x);
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
log1p(FloatType x) {
return x == 0 ? FloatType(0)
: x == -1 ? -std::numeric_limits<FloatType>::infinity()
return x == -1 ? -std::numeric_limits<FloatType>::infinity()
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: x < -1 ? std::numeric_limits<FloatType>::quiet_NaN()
: sprout::log(1 + x)
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::log1p(x)
#else
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(sprout::math::detail::log1p_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -34,8 +46,17 @@ namespace sprout {
return sprout::math::detail::log1p(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::log1p;
//
// log1p
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
log1p(ArithmeticType x) {
return sprout::math::detail::log1p(x);
}
} // namespace math
using sprout::math::log1p;

View file

@ -5,13 +5,21 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/log.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
log2_impl(T x) {
return sprout::math::log(x) / sprout::math::ln_two<T>();
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
@ -19,13 +27,16 @@ namespace sprout {
inline SPROUT_CONSTEXPR FloatType
log2(FloatType x) {
return x == 0 ? -std::numeric_limits<FloatType>::infinity()
: x == 1 ? FloatType(0)
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: x < 0 ? std::numeric_limits<FloatType>::quiet_NaN()
: sprout::log(x) / sprout::math::ln_two<FloatType>()
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::log2(x)
#else
: x == 1 ? FloatType(0)
: static_cast<FloatType>(sprout::math::detail::log2_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -35,8 +46,17 @@ namespace sprout {
return sprout::math::detail::log2(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::log2;
//
// log2
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
log2(ArithmeticType x) {
return sprout::math::detail::log2(x);
}
} // namespace math
using sprout::math::log2;

View file

@ -18,9 +18,9 @@ namespace sprout {
>
inline SPROUT_CONSTEXPR FloatType
log_a(FloatType x, FloatType y) {
return x == 2 ? sprout::log(y) / sprout::math::ln_two<FloatType>()
: x == 10 ? sprout::log(y) / sprout::math::ln_ten<FloatType>()
: sprout::log(y) / sprout::log(x)
return x == 2 ? sprout::math::log(y) / sprout::math::ln_two<FloatType>()
: x == 10 ? sprout::math::log(y) / sprout::math::ln_ten<FloatType>()
: sprout::math::log(y) / sprout::math::log(x)
;
}

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_MATH_MANIPULATIONS_HPP
#define SPROUT_MATH_MANIPULATIONS_HPP
#include <sprout/config.hpp>
#include <sprout/math/copysign.hpp>
#endif // #ifndef SPROUT_MATH_MANIPULATIONS_HPP

View file

@ -23,27 +23,27 @@ namespace sprout {
return x == 0
? y < 0 ? std::numeric_limits<FloatType>::infinity()
: y > 0 ? FloatType(0)
: sprout::exp(y * sprout::log(x))
: sprout::math::exp(y * sprout::math::log(x))
: x == -1 && (y == std::numeric_limits<FloatType>::infinity() || y == -std::numeric_limits<FloatType>::infinity()) ? FloatType(1)
: x == 1 ? FloatType(1)
: y == 0 ? FloatType(1)
: y == -std::numeric_limits<FloatType>::infinity()
? x < 1 && x > -1 ? std::numeric_limits<FloatType>::infinity()
: x > 1 || x < -1 ? FloatType(0)
: sprout::exp(y * sprout::log(x))
: sprout::math::exp(y * sprout::math::log(x))
: y == std::numeric_limits<FloatType>::infinity()
? x < 1 && x > -1 ? FloatType(0)
: x > 1 || x < -1 ? std::numeric_limits<FloatType>::infinity()
: sprout::exp(y * sprout::log(x))
: sprout::math::exp(y * sprout::math::log(x))
: x == -std::numeric_limits<FloatType>::infinity()
? y < 0 ? FloatType(0)
: y > 0 ? std::numeric_limits<FloatType>::infinity()
: sprout::exp(y * sprout::log(x))
: sprout::math::exp(y * sprout::math::log(x))
: x == std::numeric_limits<FloatType>::infinity()
? y < 0 ? FloatType(0)
: y > 0 ? std::numeric_limits<FloatType>::infinity()
: sprout::exp(y * sprout::log(x))
: sprout::exp(y * sprout::log(x))
: sprout::math::exp(y * sprout::math::log(x))
: sprout::math::exp(y * sprout::math::log(x))
;
}

View file

@ -13,7 +13,7 @@ namespace sprout {
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR int
inline SPROUT_CONSTEXPR bool
signbit(FloatType x) {
return x < 0;
}

View file

@ -7,6 +7,7 @@
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/cos.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
@ -32,7 +33,7 @@ namespace sprout {
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::sin(x)
#else
: x == 0 ? FloatType(0)
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(sprout::math::detail::sin_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;

View file

@ -8,21 +8,31 @@
#include <sprout/detail/pow.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/factorial.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
sinh_impl(T x, std::size_t n, std::size_t last) {
sinh_impl_1(T x, std::size_t n, std::size_t last) {
return last - n == 1
? sprout::detail::pow_n(x, 2 * n + 1) / sprout::math::factorial<T>(2 * n + 1)
: sprout::math::detail::sinh_impl(x, n, n + (last - n) / 2)
+ sprout::math::detail::sinh_impl(x, n + (last - n) / 2, last)
? sprout::detail::pow_n(x, 2 * n + 1) / sprout::math::unchecked_factorial<T>(2 * n + 1)
: sprout::math::detail::sinh_impl_1(x, n, n + (last - n) / 2)
+ sprout::math::detail::sinh_impl_1(x, n + (last - n) / 2, last)
;
}
template<typename T>
inline SPROUT_CONSTEXPR T
sinh_impl(T x) {
return x + sprout::math::detail::sinh_impl_1(
x,
1, (sprout::math::factorial_limit<T>() - 1) / 2 + 1
);
}
template<
typename FloatType,
@ -30,19 +40,16 @@ namespace sprout {
>
inline SPROUT_CONSTEXPR FloatType
sinh(FloatType x) {
typedef typename sprout::math::detail::float_compute<FloatType>::type type;
return x == 0 ? FloatType(1)
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
return x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
: static_cast<FloatType>(
static_cast<type>(x) + sprout::math::detail::sinh_impl(
static_cast<type>(x),
1, (sprout::math::factorial_limit<type>() - 1) / 2 + 1
)
)
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::sinh(x)
#else
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(sprout::math::detail::sinh_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -52,8 +59,17 @@ namespace sprout {
return sprout::math::detail::sinh(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::sinh;
//
// sinh
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
sinh(ArithmeticType x) {
return sprout::math::detail::sinh(x);
}
} // namespace math
using sprout::math::sinh;

View file

@ -6,6 +6,7 @@
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/cos.hpp>
#include <sprout/math/sin.hpp>
#include <sprout/type_traits/enabler_if.hpp>
@ -31,7 +32,7 @@ namespace sprout {
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::sin(x)
#else
: x == 0 ? FloatType(0)
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(sprout::math::detail::tan_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;

View file

@ -5,26 +5,38 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/detail/float_compute.hpp>
#include <sprout/math/copysign.hpp>
#include <sprout/math/sinh.hpp>
#include <sprout/math/cosh.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
tanh_impl(T x) {
return sprout::math::sinh(x) / sprout::math::cosh(x);
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
tanh(FloatType x) {
return x == 0 ? FloatType(0)
: x == std::numeric_limits<FloatType>::infinity() ? FloatType(1)
return x == std::numeric_limits<FloatType>::infinity() ? FloatType(1)
: x == -std::numeric_limits<FloatType>::infinity() ? FloatType(-1)
: sprout::math::sinh(x) / sprout::math::cosh(x)
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::tanh(x)
#else
: x == 0 ? sprout::math::copysign(FloatType(0), x)
: static_cast<FloatType>(sprout::math::detail::tanh_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
@ -34,8 +46,17 @@ namespace sprout {
return sprout::math::detail::tanh(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::tanh;
//
// tanh
//
template<
typename ArithmeticType,
typename sprout::enabler_if<std::is_arithmetic<ArithmeticType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType>::type
tanh(ArithmeticType x) {
return sprout::math::detail::tanh(x);
}
} // namespace math
using sprout::math::tanh;

View file

@ -249,8 +249,8 @@ namespace sprout {
template<int D, typename Engine, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
generate_10(Engine const& eng, RealType v, IntType k, IntType nm, RealType h, IntType nk) const {
return v <= h + (t_ + 1) * sprout::log(static_cast<RealType>(nm) / nk)
+ (k + RealType(0.5)) * sprout::log(nk * btrd_.r / (k + 1)) - fc(k) - fc(t_ - k)
return v <= h + (t_ + 1) * sprout::math::log(static_cast<RealType>(nm) / nk)
+ (k + RealType(0.5)) * sprout::math::log(nk * btrd_.r / (k + 1)) - fc(k) - fc(t_ - k)
? sprout::random::random_result<Engine, binomial_distribution>(k, eng, *this)
: generate<D + 1>(eng)
;
@ -264,7 +264,7 @@ namespace sprout {
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
generate_9(Engine const& eng, RealType v, IntType k, IntType nm) const {
return generate_10<D + 1>(
eng, v, k, nm, (m_ + RealType(0.5)) * sprout::log((m_ + 1) / (btrd_.r * nm)) + fc(m_) + fc(t_ - m_), t_ - k + 1
eng, v, k, nm, (m_ + RealType(0.5)) * sprout::math::log((m_ + 1) / (btrd_.r * nm)) + fc(m_) + fc(t_ - m_), t_ - k + 1
);
}
template<int D, typename Engine, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
@ -343,7 +343,7 @@ namespace sprout {
return km <= 15
? generate_7<D + 1>(eng, v, k)
: generate_8<D + 1>(
eng, sprout::log(v), k,
eng, sprout::math::log(v), k,
(km / btrd_.npq) * (((km / RealType(3.0) + RealType(0.625)) * km + RealType(1.0) / 6) / btrd_.npq + RealType(0.5)),
-km * km / (2 * btrd_.npq))
;
@ -455,8 +455,8 @@ namespace sprout {
template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
generate_10(Engine const& eng, RealType v, IntType k, IntType nm, RealType h, IntType nk) const {
return v <= h + (t_ + 1) * sprout::log(static_cast<RealType>(nm) / nk)
+ (k + RealType(0.5)) * sprout::log(nk * btrd_.r / (k + 1)) - fc(k) - fc(t_ - k)
return v <= h + (t_ + 1) * sprout::math::log(static_cast<RealType>(nm) / nk)
+ (k + RealType(0.5)) * sprout::math::log(nk * btrd_.r / (k + 1)) - fc(k) - fc(t_ - k)
? sprout::random::random_result<Engine, binomial_distribution>(k, eng, *this)
: generate(eng)
;
@ -465,7 +465,7 @@ namespace sprout {
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
generate_9(Engine const& eng, RealType v, IntType k, IntType nm) const {
return generate_10(
eng, v, k, nm, (m_ + RealType(0.5)) * sprout::log((m_ + 1) / (btrd_.r * nm)) + fc(m_) + fc(t_ - m_), t_ - k + 1
eng, v, k, nm, (m_ + RealType(0.5)) * sprout::math::log((m_ + 1) / (btrd_.r * nm)) + fc(m_) + fc(t_ - m_), t_ - k + 1
);
}
template<typename Engine>
@ -514,7 +514,7 @@ namespace sprout {
return km <= 15
? generate_7(eng, v, k)
: generate_8(
eng, sprout::log(v), k,
eng, sprout::math::log(v), k,
(km / btrd_.npq) * (((km / RealType(3.0) + RealType(0.625)) * km + RealType(1.0) / 6) / btrd_.npq + RealType(0.5)),
-km * km / (2 * btrd_.npq))
;

View file

@ -73,7 +73,7 @@ namespace sprout {
private:
public:
static SPROUT_CONSTEXPR RealType init_log_1mp(RealType p) {
return sprout::log(1 - p);
return sprout::math::log(1 - p);
}
private:
public:
@ -83,7 +83,7 @@ namespace sprout {
template<typename Engine, typename Random>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, geometric_distribution> generate_1(Random const& rnd) const {
return sprout::random::random_result<Engine, geometric_distribution>(
static_cast<IntType>(sprout::floor(sprout::log(RealType(1) - rnd.result()) / log_1mp_)),
static_cast<IntType>(sprout::floor(sprout::math::log(RealType(1) - rnd.result()) / log_1mp_)),
rnd.engine(),
*this
);

View file

@ -134,7 +134,7 @@ namespace sprout {
generate_1_1(RealType r1, Random const& rnd) const {
return generate_2(
rnd.engine(), r1, rnd.result(),
sprout::sqrt(-result_type(2) * sprout::log(result_type(1) - rnd.result())), true
sprout::sqrt(-result_type(2) * sprout::math::log(result_type(1) - rnd.result())), true
);
}
template<typename Engine, typename Random>

View file

@ -15,51 +15,51 @@ namespace sprout {
// Const-volatility specifiers
//
template<typename T>
using remove_const_ = typename std::remove_const<T>::type;
using remove_const_t = typename std::remove_const<T>::type;
template<typename T>
using remove_volatile_ = typename std::remove_volatile<T>::type;
using remove_volatile_t = typename std::remove_volatile<T>::type;
template<typename T>
using remove_cv_ = typename std::remove_cv<T>::type;
using remove_cv_t = typename std::remove_cv<T>::type;
template<typename T>
using add_const_ = typename std::add_const<T>::type;
using add_const_t = typename std::add_const<T>::type;
template<typename T>
using add_volatile_ = typename std::add_volatile<T>::type;
using add_volatile_t = typename std::add_volatile<T>::type;
template<typename T>
using add_cv_ = typename std::add_cv<T>::type;
using add_cv_t = typename std::add_cv<T>::type;
//
// References
//
template<typename T>
using remove_reference_ = typename std::remove_reference<T>::type;
using remove_reference_t = typename std::remove_reference<T>::type;
template<typename T>
using add_lvalue_reference_ = typename std::add_lvalue_reference<T>::type;
using add_lvalue_reference_t = typename std::add_lvalue_reference<T>::type;
template<typename T>
using add_rvalue_reference_ = typename std::add_rvalue_reference<T>::type;
using add_rvalue_reference_t = typename std::add_rvalue_reference<T>::type;
//
// Pointers
//
template<typename T>
using remove_pointer_ = typename std::remove_pointer<T>::type;
using remove_pointer_t = typename std::remove_pointer<T>::type;
template<typename T>
using add_pointer_ = typename std::add_pointer<T>::type;
using add_pointer_t = typename std::add_pointer<T>::type;
//
// Sign modifiers
//
template<typename T>
using make_signed_ = typename std::make_signed<T>::type;
using make_signed_t = typename std::make_signed<T>::type;
template<typename T>
using make_unsigned_ = typename std::make_unsigned<T>::type;
using make_unsigned_t = typename std::make_unsigned<T>::type;
//
// Arrays
//
template<typename T>
using remove_extent_ = typename std::remove_extent<T>::type;
using remove_extent_t = typename std::remove_extent<T>::type;
template<typename T>
using remove_all_extents_ = typename std::remove_all_extents<T>::type;
using remove_all_extents_t = typename std::remove_all_extents<T>::type;
//
// Miscellaneous transformations
@ -68,73 +68,73 @@ namespace sprout {
std::size_t Len,
std::size_t Align = std::alignment_of<typename std::aligned_storage<Len>::type>::value
>
using aligned_storage_ = typename std::aligned_storage<Len, Align>::type;
using aligned_storage_t = typename std::aligned_storage<Len, Align>::type;
// ???
//template<std::size_t Len, typename... Types>
//using aligned_union_ = typename std::aligned_union<Len, Types...>::type;
//using aligned_union_t = typename std::aligned_union<Len, Types...>::type;
template<typename T>
using decay_ = typename std::decay<T>::type;
using decay_t = typename std::decay<T>::type;
template<bool B, typename T = void>
using enable_if_ = typename std::enable_if<B, T>::type;
using enable_if_t = typename std::enable_if<B, T>::type;
template<bool B, typename T, typename F>
using conditional_ = typename std::conditional<B, T, F>::type;
using conditional_t = typename std::conditional<B, T, F>::type;
template<typename... Types>
using common_type_ = typename std::common_type<Types...>::type;
using common_type_t = typename std::common_type<Types...>::type;
template<typename T>
using underlying_type_ = typename std::underlying_type<T>::type;
using underlying_type_t = typename std::underlying_type<T>::type;
template<typename F, typename... ArgTypes>
using result_of_ = typename std::result_of<F(ArgTypes...)>::type;
using result_of_t = typename std::result_of<F(ArgTypes...)>::type;
//
// Const-volatility specifiers
//
template<typename T>
using remove_const = sprout::remove_const_<T>;
using remove_const = sprout::remove_const_t<T>;
template<typename T>
using remove_volatile = sprout::remove_volatile_<T>;
using remove_volatile = sprout::remove_volatile_t<T>;
template<typename T>
using remove_cv = sprout::remove_cv_<T>;
using remove_cv = sprout::remove_cv_t<T>;
template<typename T>
using add_const = sprout::add_const_<T>;
using add_const = sprout::add_const_t<T>;
template<typename T>
using add_volatile = sprout::add_volatile_<T>;
using add_volatile = sprout::add_volatile_t<T>;
template<typename T>
using add_cv = sprout::add_cv_<T>;
using add_cv = sprout::add_cv_t<T>;
//
// References
//
template<typename T>
using remove_reference = sprout::remove_reference_<T>;
using remove_reference = sprout::remove_reference_t<T>;
template<typename T>
using add_lvalue_reference = sprout::add_lvalue_reference_<T>;
using add_lvalue_reference = sprout::add_lvalue_reference_t<T>;
template<typename T>
using add_rvalue_reference = sprout::add_rvalue_reference_<T>;
using add_rvalue_reference = sprout::add_rvalue_reference_t<T>;
//
// Pointers
//
template<typename T>
using remove_pointer = sprout::remove_pointer_<T>;
using remove_pointer = sprout::remove_pointer_t<T>;
template<typename T>
using add_pointer = sprout::add_pointer_<T>;
using add_pointer = sprout::add_pointer_t<T>;
//
// Sign modifiers
//
template<typename T>
using make_signed = sprout::make_signed_<T>;
using make_signed = sprout::make_signed_t<T>;
template<typename T>
using make_unsigned = sprout::make_unsigned_<T>;
using make_unsigned = sprout::make_unsigned_t<T>;
//
// Arrays
//
template<typename T>
using remove_extent = sprout::remove_extent_<T>;
using remove_extent = sprout::remove_extent_t<T>;
template<typename T>
using remove_all_extents = sprout::remove_all_extents_<T>;
using remove_all_extents = sprout::remove_all_extents_t<T>;
//
// Miscellaneous transformations
@ -143,23 +143,23 @@ namespace sprout {
std::size_t Len,
std::size_t Align = std::alignment_of<typename std::aligned_storage<Len>::type>::value
>
using aligned_storage = sprout::aligned_storage_<Len, Align>;
using aligned_storage = sprout::aligned_storage_t<Len, Align>;
// ???
//template<std::size_t Len, typename... Types>
//using aligned_union = sprout::aligned_union_<Len, Types...>;
//using aligned_union = sprout::aligned_union_t<Len, Types...>;
template<typename T>
using decay = sprout::decay_<T>;
using decay = sprout::decay_t<T>;
template<bool B, typename T = void>
using enable_if = sprout::enable_if_<B, T>;
using enable_if = sprout::enable_if_t<B, T>;
template<bool B, typename T, typename F>
using conditional = sprout::conditional_<B, T, F>;
using conditional = sprout::conditional_t<B, T, F>;
template<typename... Types>
using common_type = sprout::common_type_<Types...>;
using common_type = sprout::common_type_t<Types...>;
template<typename T>
using underlying_type = sprout::underlying_type_<T>;
using underlying_type = sprout::underlying_type_t<T>;
// ???
//template<typename F, typename... ArgTypes>
//using result_of = sprout::result_of_<F, ArgTypes...>;
//using result_of = sprout::result_of_t<F, ArgTypes...>;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -55,7 +55,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename... Types>
using arithmetic_promote_ = typename sprout::arithmetic_promote<Types...>::type;
using arithmetic_promote_t = typename sprout::arithmetic_promote<Types...>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -15,7 +15,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename... Types>
using common_decay_ = typename sprout::common_decay<Types...>::type;
using common_decay_t = typename sprout::common_decay<Types...>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -17,7 +17,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using const_reference_ = typename sprout::const_reference<T>::type;
using const_reference_t = typename sprout::const_reference<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -21,7 +21,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<bool C>
using enabler_if_ = typename sprout::enabler_if<C>::type;
using enabler_if_t = typename sprout::enabler_if<C>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -66,7 +66,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename... Types>
using float_promote_ = typename sprout::float_promote<Types...>::type;
using float_promote_t = typename sprout::float_promote<Types...>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -15,7 +15,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using identity_ = typename sprout::identity<T>::type;
using identity_t = typename sprout::identity<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -43,7 +43,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_c_str_ = typename sprout::is_c_str<T>::type;
using is_c_str_t = typename sprout::is_c_str<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -43,7 +43,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_char_type_ = typename sprout::is_char_type<T>::type;
using is_char_type_t = typename sprout::is_char_type<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -25,7 +25,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Arg>
using is_convert_constructible_ = typename sprout::is_convert_constructible<T, Arg>::type;
using is_convert_constructible_t = typename sprout::is_convert_constructible<T, Arg>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -18,7 +18,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_int_ = typename sprout::is_int<T>::type;
using is_int_t = typename sprout::is_int<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -18,7 +18,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_uint_ = typename sprout::is_uint<T>::type;
using is_uint_t = typename sprout::is_uint<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -17,7 +17,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using lvalue_reference_ = typename sprout::lvalue_reference<T>::type;
using lvalue_reference_t = typename sprout::lvalue_reference<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -17,7 +17,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using remove_cvref_ = typename sprout::remove_cvref<T>::type;
using remove_cvref_t = typename sprout::remove_cvref<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -20,7 +20,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using remove_shallow_const_ = typename sprout::remove_shallow_const<T>::type;
using remove_shallow_const_t = typename sprout::remove_shallow_const<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -28,7 +28,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using remove_shallow_cv_ = typename sprout::remove_shallow_cv<T>::type;
using remove_shallow_cv_t = typename sprout::remove_shallow_cv<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -18,7 +18,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using remove_shallow_cvref_ = typename sprout::remove_shallow_cvref<T>::type;
using remove_shallow_cvref_t = typename sprout::remove_shallow_cvref<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout

View file

@ -20,7 +20,7 @@ namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using remove_shallow_volatile_ = typename sprout::remove_shallow_volatile<T>::type;
using remove_shallow_volatile_t = typename sprout::remove_shallow_volatile<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout