2 // Copyright 2005-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // A non-portable hash function form non-zero floats on x86.
8 // Even if you're on an x86 platform, this might not work if their floating
9 // point isn't set up as this expects. So this should only be used if it's
10 // absolutely certain that it will work.
12 #if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_X86_HEADER)
13 #define BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_X86_HEADER
15 #include <boost/cstdint.hpp>
17 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
25 inline void hash_float_combine(std::size_t& seed, std::size_t value)
27 seed ^= value + (seed<<6) + (seed>>2);
30 inline std::size_t float_hash_impl(float v)
32 boost::uint32_t* ptr = (boost::uint32_t*)&v;
33 std::size_t seed = *ptr;
37 inline std::size_t float_hash_impl(double v)
39 boost::uint32_t* ptr = (boost::uint32_t*)&v;
40 std::size_t seed = *ptr++;
41 hash_float_combine(seed, *ptr);
45 inline std::size_t float_hash_impl(long double v)
47 boost::uint32_t* ptr = (boost::uint32_t*)&v;
48 std::size_t seed = *ptr++;
49 hash_float_combine(seed, *ptr++);
50 hash_float_combine(seed, *(boost::uint16_t*)ptr);