mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
workaround for no c++11 numeric_limits
This commit is contained in:
parent
ce16e24637
commit
7a1974742a
110 changed files with 727 additions and 436 deletions
|
@ -2,9 +2,9 @@
|
|||
#define SPROUT_MATH_LOGB_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/limits.hpp>
|
||||
#include <sprout/detail/pow.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/detail/float_compute.hpp>
|
||||
|
@ -22,7 +22,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR T
|
||||
logb_impl_3_neg_lo(T x, T x0, T base, T exp) {
|
||||
return base < 1 ? sprout::math::detail::logb_impl_3_neg_lo(
|
||||
x, x0 * std::numeric_limits<T>::radix, x / (x0 / std::numeric_limits<T>::radix), exp - 1
|
||||
x, x0 * sprout::numeric_limits<T>::radix, x / (x0 / sprout::numeric_limits<T>::radix), exp - 1
|
||||
)
|
||||
: exp
|
||||
;
|
||||
|
@ -30,8 +30,8 @@ namespace sprout {
|
|||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
logb_impl_3_neg_hi(T x, T x0, T base, T exp) {
|
||||
return !(base < std::numeric_limits<T>::radix) ? sprout::math::detail::logb_impl_3_neg_hi(
|
||||
x, x0 / std::numeric_limits<T>::radix, x / (x0 * std::numeric_limits<T>::radix), exp + 1
|
||||
return !(base < sprout::numeric_limits<T>::radix) ? sprout::math::detail::logb_impl_3_neg_hi(
|
||||
x, x0 / sprout::numeric_limits<T>::radix, x / (x0 * sprout::numeric_limits<T>::radix), exp + 1
|
||||
)
|
||||
: exp
|
||||
;
|
||||
|
@ -40,7 +40,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR T
|
||||
logb_impl_3_pos_lo(T x, T x0, T base, T exp) {
|
||||
return base < 1 ? sprout::math::detail::logb_impl_3_pos_lo(
|
||||
x, x0 * std::numeric_limits<T>::radix, x / (x0 / std::numeric_limits<T>::radix), exp - 1
|
||||
x, x0 * sprout::numeric_limits<T>::radix, x / (x0 / sprout::numeric_limits<T>::radix), exp - 1
|
||||
)
|
||||
: exp
|
||||
;
|
||||
|
@ -48,8 +48,8 @@ namespace sprout {
|
|||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
logb_impl_3_pos_hi(T x, T x0, T base, T exp) {
|
||||
return !(base < std::numeric_limits<T>::radix) ? sprout::math::detail::logb_impl_3_pos_hi(
|
||||
x, x0 / std::numeric_limits<T>::radix, x / (x0 * std::numeric_limits<T>::radix), exp + 1
|
||||
return !(base < sprout::numeric_limits<T>::radix) ? sprout::math::detail::logb_impl_3_pos_hi(
|
||||
x, x0 / sprout::numeric_limits<T>::radix, x / (x0 * sprout::numeric_limits<T>::radix), exp + 1
|
||||
)
|
||||
: exp
|
||||
;
|
||||
|
@ -59,17 +59,17 @@ namespace sprout {
|
|||
logb_impl_3(T x, T x0, T base, T exp) {
|
||||
return x < 1
|
||||
? base < 1 ? sprout::math::detail::logb_impl_3_neg_lo(
|
||||
x, x0 * std::numeric_limits<T>::radix, x / (x0 / std::numeric_limits<T>::radix), exp - 1
|
||||
x, x0 * sprout::numeric_limits<T>::radix, x / (x0 / sprout::numeric_limits<T>::radix), exp - 1
|
||||
)
|
||||
: !(base < std::numeric_limits<T>::radix) ? sprout::math::detail::logb_impl_3_neg_hi(
|
||||
x, x0 / std::numeric_limits<T>::radix, x / (x0 * std::numeric_limits<T>::radix), exp + 1
|
||||
: !(base < sprout::numeric_limits<T>::radix) ? sprout::math::detail::logb_impl_3_neg_hi(
|
||||
x, x0 / sprout::numeric_limits<T>::radix, x / (x0 * sprout::numeric_limits<T>::radix), exp + 1
|
||||
)
|
||||
: exp
|
||||
: base < 1 ? sprout::math::detail::logb_impl_3_pos_lo(
|
||||
x, x0 * std::numeric_limits<T>::radix, x / (x0 / std::numeric_limits<T>::radix), exp - 1
|
||||
x, x0 * sprout::numeric_limits<T>::radix, x / (x0 / sprout::numeric_limits<T>::radix), exp - 1
|
||||
)
|
||||
: !(base < std::numeric_limits<T>::radix) ? sprout::math::detail::logb_impl_3_pos_hi(
|
||||
x, x0 / std::numeric_limits<T>::radix, x / (x0 * std::numeric_limits<T>::radix), exp + 1
|
||||
: !(base < sprout::numeric_limits<T>::radix) ? sprout::math::detail::logb_impl_3_pos_hi(
|
||||
x, x0 / sprout::numeric_limits<T>::radix, x / (x0 * sprout::numeric_limits<T>::radix), exp + 1
|
||||
)
|
||||
: exp
|
||||
;
|
||||
|
@ -83,14 +83,14 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR T
|
||||
logb_impl_1(T x, T exp) {
|
||||
return sprout::math::detail::logb_impl_2(
|
||||
x, sprout::detail::pow_n(T(std::numeric_limits<T>::radix), sprout::math::itrunc<std::intmax_t>(exp)), exp
|
||||
x, sprout::detail::pow_n(T(sprout::numeric_limits<T>::radix), sprout::math::itrunc<std::intmax_t>(exp)), exp
|
||||
);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
logb_impl(T x) {
|
||||
return x < 0 ? sprout::math::detail::logb_impl_1(-x, sprout::math::trunc(sprout::math::log_a(T(std::numeric_limits<T>::radix), -x)))
|
||||
: sprout::math::detail::logb_impl_1(x, sprout::math::trunc(sprout::math::log_a(T(std::numeric_limits<T>::radix), x)))
|
||||
return x < 0 ? sprout::math::detail::logb_impl_1(-x, sprout::math::trunc(sprout::math::log_a(T(sprout::numeric_limits<T>::radix), -x)))
|
||||
: sprout::math::detail::logb_impl_1(x, sprout::math::trunc(sprout::math::log_a(T(sprout::numeric_limits<T>::radix), x)))
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -101,16 +101,16 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR FloatType
|
||||
logb(FloatType x) {
|
||||
return sprout::math::isnan(x) ? x
|
||||
: x == 0 ? -std::numeric_limits<FloatType>::infinity()
|
||||
: x == 0 ? -sprout::numeric_limits<FloatType>::infinity()
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
# if defined(__GNUC__)
|
||||
: x == -std::numeric_limits<FloatType>::infinity()
|
||||
? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -sprout::numeric_limits<FloatType>::infinity()
|
||||
? sprout::numeric_limits<FloatType>::infinity()
|
||||
# endif
|
||||
: std::logb(x)
|
||||
#else
|
||||
: x == std::numeric_limits<FloatType>::infinity() || x == -std::numeric_limits<FloatType>::infinity()
|
||||
? std::numeric_limits<FloatType>::infinity()
|
||||
: x == sprout::numeric_limits<FloatType>::infinity() || x == -sprout::numeric_limits<FloatType>::infinity()
|
||||
? sprout::numeric_limits<FloatType>::infinity()
|
||||
: static_cast<FloatType>(sprout::math::detail::logb_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
|
||||
#endif
|
||||
;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue