1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-10-05 13:00:00 +00:00

fix math::log implementation

support std::hash
This commit is contained in:
bolero-MURAKAMI 2013-02-07 03:11:17 +09:00
commit 66da9f4fea
20 changed files with 288 additions and 5 deletions

View file

@ -10,5 +10,8 @@
#include <sprout/math/log10.hpp>
#include <sprout/math/log2.hpp>
#include <sprout/math/log1p.hpp>
#include <sprout/math/ldexp.hpp>
#include <sprout/math/scalbn.hpp>
#include <sprout/math/scalbln.hpp>
#endif // #ifndef SPROUT_MATH_EXPONENTIAL_HPP

38
sprout/math/ldexp.hpp Normal file
View file

@ -0,0 +1,38 @@
#ifndef SPROUT_MATH_LDEXP_HPP
#define SPROUT_MATH_LDEXP_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/detail/pow.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
ldexp(FloatType x, int exp) {
return static_cast<FloatType>(x * sprout::detail::pow_n(FloatType(2), exp));
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR double
ldexp(IntType x, int exp) {
return sprout::math::detail::ldexp(static_cast<double>(x), exp);
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::ldexp;
} // namespace math
using sprout::math::ldexp;
} // namespace sprout
#endif // #ifndef SPROUT_MATH_LDEXP_HPP

View file

@ -42,7 +42,8 @@ namespace sprout {
typedef double type;
return x == 0 ? std::numeric_limits<FloatType>::quiet_NaN()
: !(x > 0) ? -std::numeric_limits<FloatType>::infinity()
: static_cast<FloatType>(sprout::math::detail::log_impl(x))
: x < 1 ? static_cast<FloatType>(-sprout::math::detail::log_impl(type(1) / static_cast<type>(x)))
: static_cast<FloatType>(sprout::math::detail::log_impl(static_cast<type>(x)))
;
}

39
sprout/math/scalbln.hpp Normal file
View file

@ -0,0 +1,39 @@
#ifndef SPROUT_MATH_SCALBLN_HPP
#define SPROUT_MATH_SCALBLN_HPP
#include <cfloat>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/detail/pow.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
scalbln(FloatType x, long exp) {
return static_cast<FloatType>(x * sprout::detail::pow_n(FloatType(FLT_RADIX), exp));
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR double
scalbln(IntType x, long exp) {
return sprout::math::detail::scalbln(static_cast<double>(x), exp);
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::scalbln;
} // namespace math
using sprout::math::scalbln;
} // namespace sprout
#endif // #ifndef SPROUT_MATH_SCALBLN_HPP

39
sprout/math/scalbn.hpp Normal file
View file

@ -0,0 +1,39 @@
#ifndef SPROUT_MATH_SCALBN_HPP
#define SPROUT_MATH_SCALBN_HPP
#include <cfloat>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/detail/pow.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
scalbn(FloatType x, int exp) {
return static_cast<FloatType>(x * sprout::detail::pow_n(FloatType(FLT_RADIX), exp));
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR double
scalbn(IntType x, int exp) {
return sprout::math::detail::scalbn(static_cast<double>(x), exp);
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::scalbn;
} // namespace math
using sprout::math::scalbn;
} // namespace sprout
#endif // #ifndef SPROUT_MATH_SCALBN_HPP