1
0
Fork 0
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:
bolero-MURAKAMI 2013-08-07 00:15:09 +09:00
parent ce16e24637
commit 7a1974742a
110 changed files with 727 additions and 436 deletions

View file

@ -2,8 +2,8 @@
#define SPROUT_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_HPP
#include <cstddef>
#include <limits>
#include <sprout/config.hpp>
#include <sprout/limits.hpp>
#include <sprout/functional/hash/hash_fwd.hpp>
#include <sprout/math/fpclassify.hpp>
#include <sprout/math/ldexp.hpp>
@ -21,7 +21,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR std::size_t
float_hash_value_impl_4(T v, int exp, std::size_t seed, std::size_t length, std::size_t i = 0) {
return i != length ? sprout::detail::float_hash_value_impl_4(
sprout::ldexp(v - static_cast<T>(static_cast<std::size_t>(v)), std::numeric_limits<std::size_t>::digits),
sprout::ldexp(v - static_cast<T>(static_cast<std::size_t>(v)), sprout::numeric_limits<std::size_t>::digits),
exp, sprout::detail::hash_float_combine(seed, static_cast<std::size_t>(v)),
length, i + 1
)
@ -32,22 +32,22 @@ namespace sprout {
inline SPROUT_CONSTEXPR std::size_t
float_hash_value_impl_3(T v, int exp) {
return sprout::detail::float_hash_value_impl_4(
sprout::ldexp(v - static_cast<T>(static_cast<std::size_t>(v)), std::numeric_limits<std::size_t>::digits),
sprout::ldexp(v - static_cast<T>(static_cast<std::size_t>(v)), sprout::numeric_limits<std::size_t>::digits),
exp, static_cast<std::size_t>(v),
(std::numeric_limits<T>::digits * sprout::detail::static_log2<std::numeric_limits<T>::radix>::value + std::numeric_limits<std::size_t>::digits - 1)
/ std::numeric_limits<std::size_t>::digits
(sprout::numeric_limits<T>::digits * sprout::detail::static_log2<sprout::numeric_limits<T>::radix>::value + sprout::numeric_limits<std::size_t>::digits - 1)
/ sprout::numeric_limits<std::size_t>::digits
);
}
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
float_hash_value_impl_2(T v, int exp) {
return sprout::detail::float_hash_value_impl_3(sprout::ldexp(v, std::numeric_limits<std::size_t>::digits), exp);
return sprout::detail::float_hash_value_impl_3(sprout::ldexp(v, sprout::numeric_limits<std::size_t>::digits), exp);
}
template<typename T, typename P>
inline SPROUT_CONSTEXPR std::size_t
float_hash_value_impl_1(P const& p) {
return ((p.first) < 0) ? sprout::detail::float_hash_value_impl_2(
-p.first, p.second + (std::numeric_limits<T>::max_exponent - std::numeric_limits<T>::min_exponent)
-p.first, p.second + (sprout::numeric_limits<T>::max_exponent - sprout::numeric_limits<T>::min_exponent)
)
: sprout::detail::float_hash_value_impl_2(p.first, p.second)
;

View file

@ -2,10 +2,10 @@
#define SPROUT_FUNCTIONAL_HASH_HASH_VALUE_TRAITS_HPP
#include <cstddef>
#include <limits>
#include <functional>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/limits.hpp>
#include <sprout/functional/hash/hash_fwd.hpp>
#include <sprout/functional/hash/detail/hash_float.hpp>
@ -47,7 +47,7 @@ namespace sprout {
length,
seed ^ static_cast<std::size_t>((positive >> i) + (seed << 6) + (seed >> 2)),
positive,
i - std::numeric_limits<std::size_t>::digits
i - sprout::numeric_limits<std::size_t>::digits
)
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
;
@ -55,14 +55,14 @@ namespace sprout {
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
hash_value_signed_1(T val, int length, std::size_t seed, T positive) {
return hash_value_signed_2(val, length, seed, positive, length * std::numeric_limits<std::size_t>::digits);
return hash_value_signed_2(val, length, seed, positive, length * sprout::numeric_limits<std::size_t>::digits);
}
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
hash_value_signed(T val) {
return sprout::hash_detail::hash_value_signed_1(
val,
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
(sprout::numeric_limits<T>::digits - 1) / sprout::numeric_limits<std::size_t>::digits,
0,
val < 0 ? -1 - val : val
);
@ -76,7 +76,7 @@ namespace sprout {
val,
length,
seed ^ static_cast<std::size_t>((val >> i) + (seed << 6) + (seed >> 2)),
i - std::numeric_limits<std::size_t>::digits
i - sprout::numeric_limits<std::size_t>::digits
)
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
;
@ -84,14 +84,14 @@ namespace sprout {
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
hash_value_unsigned_1(T val, int length, std::size_t seed) {
return hash_value_unsigned_2(val, length, seed, length * std::numeric_limits<std::size_t>::digits);
return hash_value_unsigned_2(val, length, seed, length * sprout::numeric_limits<std::size_t>::digits);
}
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
hash_value_unsigned(T val) {
return sprout::hash_detail::hash_value_unsigned_1(
val,
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
(sprout::numeric_limits<T>::digits - 1) / sprout::numeric_limits<std::size_t>::digits,
0
);
}