fix doc example typo
[boost.git] / boost / functional / hash / detail / float_functions.hpp
blob69cf91a1515fe16b3d515f8db3a104124f0e0ba6
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 #if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP)
7 #define BOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP
9 #include <boost/config/no_tr1/cmath.hpp>
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
12 # pragma once
13 #endif
15 // The C++ standard requires that the C float functions are overloarded
16 // for float, double and long double in the std namespace, but some of the older
17 // library implementations don't support this. On some that don't, the C99
18 // float functions (frexpf, frexpl, etc.) are available.
20 // Some of this is based on guess work. If I don't know any better I assume that
21 // the standard C++ overloaded functions are available. If they're not then this
22 // means that the argument is cast to a double and back, which is inefficient
23 // and will give pretty bad results for long doubles - so if you know better
24 // let me know.
26 // STLport:
27 #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
28 # if (defined(__GNUC__) && __GNUC__ < 3 && (defined(linux) || defined(__linux) || defined(__linux__))) || defined(__DMC__)
29 # define BOOST_HASH_USE_C99_FLOAT_FUNCS
30 # elif defined(BOOST_MSVC) && BOOST_MSVC < 1300
31 # define BOOST_HASH_USE_C99_FLOAT_FUNCS
32 # else
33 # define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
34 # endif
36 // Roguewave:
38 // On borland 5.51, with roguewave 2.1.1 the standard C++ overloads aren't
39 // defined, but for the same version of roguewave on sunpro they are.
40 #elif defined(_RWSTD_VER)
41 # if defined(__BORLANDC__)
42 # define BOOST_HASH_USE_C99_FLOAT_FUNCS
43 # define BOOST_HASH_C99_NO_FLOAT_FUNCS
44 # elif defined(__DECCXX)
45 # define BOOST_HASH_USE_C99_FLOAT_FUNCS
46 # else
47 # define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
48 # endif
50 // libstdc++ (gcc 3.0 onwards, I think)
51 #elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
52 # define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
54 // SGI:
55 #elif defined(__STL_CONFIG_H)
56 # if defined(linux) || defined(__linux) || defined(__linux__)
57 # define BOOST_HASH_USE_C99_FLOAT_FUNCS
58 # else
59 # define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
60 # endif
62 // vxWorks. It has its own math library, but uses Dinkumware STL
63 #elif defined(__VXWORKS__)
64 # define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
66 // Dinkumware.
67 #elif (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER)
68 // Some versions of Visual C++ don't seem to have the C++ overloads but they
69 // all seem to have the c99 float overloads
70 # if defined(BOOST_MSVC)
71 # define BOOST_HASH_USE_C99_FLOAT_FUNCS
72 // On other platforms the C++ overloads seem to have been introduced sometime
73 // before 402.
74 # elif defined(_CPPLIB_VER) && (_CPPLIB_VER >= 402)
75 # define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
76 # else
77 # define BOOST_HASH_USE_C99_FLOAT_FUNCS
78 # endif
80 // Digital Mars
81 #elif defined(__DMC__)
82 # define BOOST_HASH_USE_C99_FLOAT_FUNCS
84 // Use overloaded float functions by default.
85 #else
86 # define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
87 #endif
89 namespace boost
91 namespace hash_detail
94 inline float call_ldexp(float v, int exp)
96 using namespace std;
97 #if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) || \
98 defined(BOOST_HASH_C99_NO_FLOAT_FUNCS)
99 return ldexp(v, exp);
100 #else
101 return ldexpf(v, exp);
102 #endif
105 inline double call_ldexp(double v, int exp)
107 using namespace std;
108 return ldexp(v, exp);
111 inline long double call_ldexp(long double v, int exp)
113 using namespace std;
114 #if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS)
115 return ldexp(v, exp);
116 #else
117 return ldexpl(v, exp);
118 #endif
121 inline float call_frexp(float v, int* exp)
123 using namespace std;
124 #if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) || \
125 defined(BOOST_HASH_C99_NO_FLOAT_FUNCS)
126 return frexp(v, exp);
127 #else
128 return frexpf(v, exp);
129 #endif
132 inline double call_frexp(double v, int* exp)
134 using namespace std;
135 return frexp(v, exp);
138 inline long double call_frexp(long double v, int* exp)
140 using namespace std;
141 #if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS)
142 return frexp(v, exp);
143 #else
144 return frexpl(v, exp);
145 #endif
150 #if defined(BOOST_HASH_USE_C99_FLOAT_FUNCS)
151 #undef BOOST_HASH_USE_C99_FLOAT_FUNCS
152 #endif
154 #if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS)
155 #undef BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
156 #endif
158 #if defined(BOOST_HASH_C99_NO_FLOAT_FUNCS)
159 #undef BOOST_HASH_C99_NO_FLOAT_FUNCS
160 #endif
162 #endif