]> git.lyx.org Git - features.git/blob - boost/boost/functional/hash/detail/hash_float.hpp
boost: add eol property
[features.git] / boost / boost / functional / hash / detail / hash_float.hpp
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 #if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_HEADER)
7 #define BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_HEADER
8
9 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
10 # pragma once
11 #endif
12
13 #include <boost/config.hpp>
14 #include <boost/functional/hash/detail/float_functions.hpp>
15 #include <boost/functional/hash/detail/limits.hpp>
16 #include <boost/integer/static_log2.hpp>
17 #include <boost/cstdint.hpp>
18 #include <boost/assert.hpp>
19
20 // Include hash implementation for the current platform.
21
22 // Cygwn
23 #if defined(__CYGWIN__)
24 #  if defined(__i386__) || defined(_M_IX86)
25 #    include <boost/functional/hash/detail/hash_float_x86.hpp>
26 #  else
27 #    include <boost/functional/hash/detail/hash_float_generic.hpp>
28 #  endif
29 #else
30 #  include <boost/functional/hash/detail/hash_float_generic.hpp>
31 #endif
32
33 // Can we use fpclassify?
34
35 // STLport
36 #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
37 #define BOOST_HASH_USE_FPCLASSIFY 0
38
39 // GNU libstdc++ 3
40 #elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
41 #  if (defined(__USE_ISOC99) || defined(_GLIBCXX_USE_C99_MATH)) && \
42       !(defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
43 #    define BOOST_HASH_USE_FPCLASSIFY 1
44 #  else
45 #    define BOOST_HASH_USE_FPCLASSIFY 0
46 #  endif
47
48 // Everything else
49 #else
50 #  define BOOST_HASH_USE_FPCLASSIFY 0
51 #endif
52
53 #if BOOST_HASH_USE_FPCLASSIFY
54
55 #include <boost/config/no_tr1/cmath.hpp>
56
57 namespace boost
58 {
59     namespace hash_detail
60     {
61         template <class T>
62         inline std::size_t float_hash_value(T v)
63         {
64             using namespace std;
65             switch (fpclassify(v)) {
66             case FP_ZERO:
67                 return 0;
68             case FP_INFINITE:
69                 return (std::size_t)(v > 0 ? -1 : -2);
70             case FP_NAN:
71                 return (std::size_t)(-3);
72             case FP_NORMAL:
73             case FP_SUBNORMAL:
74                 return float_hash_impl(v);
75             default:
76                 BOOST_ASSERT(0);
77                 return 0;
78             }
79         }
80     }
81 }
82
83 #else // !BOOST_HASH_USE_FPCLASSIFY
84
85 namespace boost
86 {
87     namespace hash_detail
88     {
89         template <class T>
90         inline std::size_t float_hash_value(T v)
91         {
92             return v == 0 ? 0 : float_hash_impl(v);
93         }
94     }
95 }
96
97 #endif // BOOST_HASH_USE_FPCLASSIFY
98
99 #undef BOOST_HASH_USE_FPCLASSIFY
100
101 #endif