source: NonGTP/Boost/boost/functional/detail/float_functions.hpp @ 857

Revision 857, 4.4 KB checked in by igarcia, 18 years ago (diff)
Line 
1//  (C) Copyright Daniel James 2005.
2//  Use, modification and distribution are subject to the
3//  Boost Software License, Version 1.0. (See accompanying file
4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#if !defined(BOOST_FUNCTIONAL_DETAIL_FLOAT_FUNCTIONS_HPP)
7#define BOOST_FUNCTIONAL_DETAIL_FLOAT_FUNCTIONS_HPP
8
9#if defined(_MSC_VER) && (_MSC_VER >= 1020)
10# pragma once
11#endif
12
13// The C++ standard requires that the C float functions are overloarded
14// for float, double and long double in the std namespace, but some of the older
15// library implementations don't support this. On some that don't, the C99
16// float functions (frexpf, frexpl, etc.) are available.
17//
18// Some of this is based on guess work. If I don't know any better I assume that
19// the standard C++ overloaded functions are available. If they're not then this
20// means that the argument is cast to a double and back, which is inefficient
21// and will give pretty bad results for long doubles - so if you know better
22// let me know.
23
24// STLport:
25#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
26#  if defined(__GNUC__) && __GNUC__ < 3 && (defined(linux) || defined(__linux) || defined(__linux__))
27#    define BOOST_HASH_USE_C99_FLOAT_FUNCS
28#  elif defined(BOOST_MSVC) && BOOST_MSVC <= 1200
29#    define BOOST_HASH_USE_C99_FLOAT_FUNCS
30#  else
31#    define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
32#  endif
33
34// Roguewave:
35//
36// On borland 5.51, with roguewave 2.1.1 the standard C++ overloads aren't
37// defined, but for the same version of roguewave on sunpro they are.
38#elif defined(_RWSTD_VER)
39#  if defined(__BORLANDC__)
40#    define BOOST_HASH_USE_C99_FLOAT_FUNCS
41#    define BOOST_HASH_C99_NO_FLOAT_FUNCS
42#  elif defined(__DECCXX)
43#    define BOOST_HASH_USE_C99_FLOAT_FUNCS
44#  else
45#    define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
46#  endif
47
48// libstdc++ (gcc 3.0 onwards, I think)
49#elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
50#  define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
51
52// SGI:
53#elif defined(__STL_CONFIG_H)
54#  if defined(linux) || defined(__linux) || defined(__linux__)
55#    define BOOST_HASH_USE_C99_FLOAT_FUNCS
56#  else
57#    define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
58#  endif
59
60// Dinkumware.
61#elif (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER)
62// Overloaded float functions were probably introduced in an earlier version
63// than this.
64#  if defined(_CPPLIB_VER) && (_CPPLIB_VER >= 402)
65#    define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
66#  else
67#    define BOOST_HASH_USE_C99_FLOAT_FUNCS
68#  endif
69
70// Digital Mars
71#elif defined(__DMC__)
72#  define BOOST_HASH_USE_C99_FLOAT_FUNCS
73
74// Use overloaded float functions by default.
75#else
76#  define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
77#endif
78
79namespace boost
80{
81    namespace hash_detail
82    {
83
84        inline float call_ldexp(float v, int exp)
85        {
86            using namespace std;
87#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) || \
88    defined(BOOST_HASH_C99_NO_FLOAT_FUNCS)
89            return ldexp(v, exp);
90#else
91            return ldexpf(v, exp);
92#endif
93        }
94
95        inline double call_ldexp(double v, int exp)
96        {
97            using namespace std;
98            return ldexp(v, exp);
99        }
100
101        inline long double call_ldexp(long double v, int exp)
102        {
103            using namespace std;
104#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS)
105            return ldexp(v, exp);
106#else
107            return ldexpl(v, exp);
108#endif
109        }
110
111        inline float call_frexp(float v, int* exp)
112        {
113            using namespace std;
114#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) || \
115    defined(BOOST_HASH_C99_NO_FLOAT_FUNCS)
116            return frexp(v, exp);
117#else
118            return frexpf(v, exp);
119#endif
120        }
121
122        inline double call_frexp(double v, int* exp)
123        {
124            using namespace std;
125            return frexp(v, exp);
126        }
127
128        inline long double call_frexp(long double v, int* exp)
129        {
130            using namespace std;
131#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS)
132            return frexp(v, exp);
133#else
134            return frexpl(v, exp);
135#endif
136        }
137    }
138}
139
140#if defined(BOOST_HASH_USE_C99_FLOAT_FUNCS)
141#undef BOOST_HASH_USE_C99_FLOAT_FUNCS
142#endif
143
144#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS)
145#undef BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
146#endif
147
148#if defined(BOOST_HASH_C99_NO_FLOAT_FUNCS)
149#undef BOOST_HASH_C99_NO_FLOAT_FUNCS
150#endif
151
152#endif
Note: See TracBrowser for help on using the repository browser.