Update 128 bit long double hash_value

This commit is contained in:
Peter Dimov
2022-09-20 14:49:37 +03:00
parent 75ef5a14f5
commit 034b81594d
2 changed files with 10 additions and 21 deletions

View File

@@ -289,7 +289,7 @@ namespace boost
};
// 128 bit long double
template<class T, int Digits> struct hash_float_impl<T, 128, Digits, 64>
template<class T, int Digits, std::size_t size_t_bits> struct hash_float_impl<T, 128, Digits, size_t_bits>
{
static std::size_t fn( T v )
{
@@ -298,26 +298,8 @@ namespace boost
std::size_t seed = 0;
seed = static_cast<std::size_t>( w[0] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[1] ) + hash_detail::hash_mix( seed );
return seed;
}
};
template<class T, int Digits> struct hash_float_impl<T, 128, Digits, 32>
{
static std::size_t fn( T v )
{
boost::uint32_t w[ 4 ];
std::memcpy( &w, &v, sizeof( v ) );
std::size_t seed = 0;
seed = static_cast<std::size_t>( w[0] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[1] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[2] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[3] ) + hash_detail::hash_mix( seed );
seed = hash_value( w[0] ) + hash_detail::hash_mix( seed );
seed = hash_value( w[1] ) + hash_detail::hash_mix( seed );
return seed;
}

View File

@@ -249,6 +249,13 @@ int main()
// ldbits == 128 && std::numeric_limits<long double>::digits == 113
// under ARM64 and S390x, but the values differ presumably because of
// __FLOAT_WORD_ORDER__
BOOST_TEST_EQ( hv(1.0L), 4611404543450677248ULL );
BOOST_TEST_EQ( hv(-1.0L), 13834776580305453056ULL );
BOOST_TEST_EQ( hv(3.14L), 5967435363179612952ULL );
BOOST_TEST_EQ( hv(-3.14L), 15190807400034388760ULL );
BOOST_TEST_EQ( hv(std::numeric_limits<long double>::infinity()), 9223090561878065152ULL );
BOOST_TEST_EQ( hv(-std::numeric_limits<long double>::infinity()), 18446462598732840960ULL );
}
#endif