source: vendor/nemo/current/NEMOGCM/EXTERNAL/XIOS/extern/boost/include/boost/functional/hash/detail/hash_float_x86.hpp @ 44

Last change on this file since 44 was 44, checked in by cholod, 12 years ago

Load NEMO_TMP into vendor/nemo/current.

File size: 1.6 KB
Line 
1
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)
5
6// A non-portable hash function form non-zero floats on x86.
7//
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.
11
12#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_X86_HEADER)
13#define BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_X86_HEADER
14
15#include <boost/cstdint.hpp>
16
17#if defined(_MSC_VER) && (_MSC_VER >= 1020)
18# pragma once
19#endif
20
21namespace boost
22{
23    namespace hash_detail
24    {
25        inline void hash_float_combine(std::size_t& seed, std::size_t value)
26        {
27            seed ^= value + (seed<<6) + (seed>>2);
28        }
29
30        inline std::size_t float_hash_impl(float v)
31        {
32            boost::uint32_t* ptr = (boost::uint32_t*)&v;
33            std::size_t seed = *ptr;
34            return seed;
35        }
36
37        inline std::size_t float_hash_impl(double v)
38        {
39            boost::uint32_t* ptr = (boost::uint32_t*)&v;
40            std::size_t seed = *ptr++;
41            hash_float_combine(seed, *ptr);
42            return seed;
43        }
44
45        inline std::size_t float_hash_impl(long double v)
46        {
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);
51            return seed;
52        }
53    }
54}
55
56#endif
Note: See TracBrowser for help on using the repository browser.