mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix math::log implementation
support std::hash
This commit is contained in:
parent
9140b68379
commit
66da9f4fea
20 changed files with 288 additions and 5 deletions
|
@ -1,7 +1,11 @@
|
|||
#ifndef SPROUT_DETAIL_POW_HPP
|
||||
#define SPROUT_DETAIL_POW_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/is_int.hpp>
|
||||
#include <sprout/type_traits/is_uint.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
|
@ -17,21 +21,35 @@ namespace sprout {
|
|||
return x * x * x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename T, typename IntType>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
pow_n_impl(T const& x, int n) {
|
||||
pow_n_impl(T const& x, IntType n) {
|
||||
return n == 1 ? x
|
||||
: n % 2 ? x * sprout::detail::pow2(sprout::detail::pow_n_impl(x, n / 2))
|
||||
: sprout::detail::pow2(sprout::detail::pow_n_impl(x, n / 2))
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
template<
|
||||
typename T, typename UIntType,
|
||||
typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
pow_n(T const& x, int n) {
|
||||
pow_n(T const& x, UIntType n) {
|
||||
return n == 0 ? T(1)
|
||||
: sprout::detail::pow_n_impl(x, n)
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename T, typename IntType,
|
||||
typename sprout::enabler_if<sprout::is_int<IntType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
pow_n(T const& x, IntType n) {
|
||||
return n == 0 ? T(1)
|
||||
: n > 0 ? sprout::detail::pow_n_impl(x, n)
|
||||
: T(1) / sprout::detail::pow_n_impl(x, -n)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue