diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-03-28 15:46:49 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-03-28 15:46:49 (GMT) |
commit | f53a1ef582494458301b97bf6e546be52d7ff7e8 (patch) | |
tree | 7571b5cbcbd8a8f1dd1c966c9045b6cb69f0e295 /3rdParty/Boost/src/boost/functional/hash/detail | |
parent | 638345680d72ca6acaf123f2c8c1c391f696e371 (diff) | |
download | swift-contrib-f53a1ef582494458301b97bf6e546be52d7ff7e8.zip swift-contrib-f53a1ef582494458301b97bf6e546be52d7ff7e8.tar.bz2 |
Moving submodule contents back.
Diffstat (limited to '3rdParty/Boost/src/boost/functional/hash/detail')
-rw-r--r-- | 3rdParty/Boost/src/boost/functional/hash/detail/float_functions.hpp | 162 | ||||
-rw-r--r-- | 3rdParty/Boost/src/boost/functional/hash/detail/hash_float.hpp | 197 |
2 files changed, 359 insertions, 0 deletions
diff --git a/3rdParty/Boost/src/boost/functional/hash/detail/float_functions.hpp b/3rdParty/Boost/src/boost/functional/hash/detail/float_functions.hpp new file mode 100644 index 0000000..69cf91a --- /dev/null +++ b/3rdParty/Boost/src/boost/functional/hash/detail/float_functions.hpp @@ -0,0 +1,162 @@ + +// Copyright 2005-2009 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP) +#define BOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP + +#include <boost/config/no_tr1/cmath.hpp> + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +// The C++ standard requires that the C float functions are overloarded +// for float, double and long double in the std namespace, but some of the older +// library implementations don't support this. On some that don't, the C99 +// float functions (frexpf, frexpl, etc.) are available. +// +// Some of this is based on guess work. If I don't know any better I assume that +// the standard C++ overloaded functions are available. If they're not then this +// means that the argument is cast to a double and back, which is inefficient +// and will give pretty bad results for long doubles - so if you know better +// let me know. + +// STLport: +#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) +# if (defined(__GNUC__) && __GNUC__ < 3 && (defined(linux) || defined(__linux) || defined(__linux__))) || defined(__DMC__) +# define BOOST_HASH_USE_C99_FLOAT_FUNCS +# elif defined(BOOST_MSVC) && BOOST_MSVC < 1300 +# define BOOST_HASH_USE_C99_FLOAT_FUNCS +# else +# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS +# endif + +// Roguewave: +// +// On borland 5.51, with roguewave 2.1.1 the standard C++ overloads aren't +// defined, but for the same version of roguewave on sunpro they are. +#elif defined(_RWSTD_VER) +# if defined(__BORLANDC__) +# define BOOST_HASH_USE_C99_FLOAT_FUNCS +# define BOOST_HASH_C99_NO_FLOAT_FUNCS +# elif defined(__DECCXX) +# define BOOST_HASH_USE_C99_FLOAT_FUNCS +# else +# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS +# endif + +// libstdc++ (gcc 3.0 onwards, I think) +#elif defined(__GLIBCPP__) || defined(__GLIBCXX__) +# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS + +// SGI: +#elif defined(__STL_CONFIG_H) +# if defined(linux) || defined(__linux) || defined(__linux__) +# define BOOST_HASH_USE_C99_FLOAT_FUNCS +# else +# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS +# endif + +// vxWorks. It has its own math library, but uses Dinkumware STL +#elif defined(__VXWORKS__) +# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS + +// Dinkumware. +#elif (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER) +// Some versions of Visual C++ don't seem to have the C++ overloads but they +// all seem to have the c99 float overloads +# if defined(BOOST_MSVC) +# define BOOST_HASH_USE_C99_FLOAT_FUNCS +// On other platforms the C++ overloads seem to have been introduced sometime +// before 402. +# elif defined(_CPPLIB_VER) && (_CPPLIB_VER >= 402) +# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS +# else +# define BOOST_HASH_USE_C99_FLOAT_FUNCS +# endif + +// Digital Mars +#elif defined(__DMC__) +# define BOOST_HASH_USE_C99_FLOAT_FUNCS + +// Use overloaded float functions by default. +#else +# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS +#endif + +namespace boost +{ + namespace hash_detail + { + + inline float call_ldexp(float v, int exp) + { + using namespace std; +#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) || \ + defined(BOOST_HASH_C99_NO_FLOAT_FUNCS) + return ldexp(v, exp); +#else + return ldexpf(v, exp); +#endif + } + + inline double call_ldexp(double v, int exp) + { + using namespace std; + return ldexp(v, exp); + } + + inline long double call_ldexp(long double v, int exp) + { + using namespace std; +#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) + return ldexp(v, exp); +#else + return ldexpl(v, exp); +#endif + } + + inline float call_frexp(float v, int* exp) + { + using namespace std; +#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) || \ + defined(BOOST_HASH_C99_NO_FLOAT_FUNCS) + return frexp(v, exp); +#else + return frexpf(v, exp); +#endif + } + + inline double call_frexp(double v, int* exp) + { + using namespace std; + return frexp(v, exp); + } + + inline long double call_frexp(long double v, int* exp) + { + using namespace std; +#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) + return frexp(v, exp); +#else + return frexpl(v, exp); +#endif + } + } +} + +#if defined(BOOST_HASH_USE_C99_FLOAT_FUNCS) +#undef BOOST_HASH_USE_C99_FLOAT_FUNCS +#endif + +#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) +#undef BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS +#endif + +#if defined(BOOST_HASH_C99_NO_FLOAT_FUNCS) +#undef BOOST_HASH_C99_NO_FLOAT_FUNCS +#endif + +#endif diff --git a/3rdParty/Boost/src/boost/functional/hash/detail/hash_float.hpp b/3rdParty/Boost/src/boost/functional/hash/detail/hash_float.hpp new file mode 100644 index 0000000..5d5ac34 --- /dev/null +++ b/3rdParty/Boost/src/boost/functional/hash/detail/hash_float.hpp @@ -0,0 +1,197 @@ + +// Copyright 2005-2009 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_HEADER) +#define BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_HEADER + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +#if defined(BOOST_MSVC) +#pragma warning(push) +#if BOOST_MSVC >= 1400 +#pragma warning(disable:6294) // Ill-defined for-loop: initial condition does + // not satisfy test. Loop body not executed +#endif +#endif + +#include <boost/functional/hash/detail/float_functions.hpp> +#include <boost/integer/static_log2.hpp> +#include <boost/cstdint.hpp> +#include <boost/limits.hpp> +#include <boost/assert.hpp> + +// Select implementation for the current platform. + +// Cygwn +#if defined(__CYGWIN__) +# if defined(__i386__) || defined(_M_IX86) +# define BOOST_HASH_USE_x86_BINARY_HASH +# endif + +// STLport +#elif defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) +// fpclassify aren't good enough on STLport. + +// GNU libstdc++ 3 +#elif defined(__GLIBCPP__) || defined(__GLIBCXX__) +# if (defined(__USE_ISOC99) || defined(_GLIBCXX_USE_C99_MATH)) && \ + !(defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) +# define BOOST_HASH_USE_FPCLASSIFY +# endif + +// Dinkumware Library, on Visual C++ +#elif (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER) + +// Not using _fpclass because it is only available for double. + +#endif + +// On OpenBSD, numeric_limits is not reliable for long doubles, but +// the macros defined in <float.h> are. + +#if defined(__OpenBSD__) +#include <float.h> +#endif + +namespace boost +{ + namespace hash_detail + { + template <class T> + struct limits : std::numeric_limits<T> {}; + +#if defined(__OpenBSD__) + template <> + struct limits<long double> + : std::numeric_limits<long double> + { + static long double epsilon() { + return LDBL_EPSILON; + } + + static long double (max)() { + return LDBL_MAX; + } + + static long double (min)() { + return LDBL_MIN; + } + + BOOST_STATIC_CONSTANT(int, digits = LDBL_MANT_DIG); + BOOST_STATIC_CONSTANT(int, max_exponent = LDBL_MAX_EXP); + BOOST_STATIC_CONSTANT(int, min_exponent = LDBL_MIN_EXP); + }; +#endif // __OpenBSD__ + + inline void hash_float_combine(std::size_t& seed, std::size_t value) + { + seed ^= value + (seed<<6) + (seed>>2); + } + +// A simple, non-portable hash algorithm for x86. +#if defined(BOOST_HASH_USE_x86_BINARY_HASH) + inline std::size_t float_hash_impl(float v) + { + boost::uint32_t* ptr = (boost::uint32_t*)&v; + std::size_t seed = *ptr; + return seed; + } + + inline std::size_t float_hash_impl(double v) + { + boost::uint32_t* ptr = (boost::uint32_t*)&v; + std::size_t seed = *ptr++; + hash_float_combine(seed, *ptr); + return seed; + } + + inline std::size_t float_hash_impl(long double v) + { + boost::uint32_t* ptr = (boost::uint32_t*)&v; + std::size_t seed = *ptr++; + hash_float_combine(seed, *ptr++); + hash_float_combine(seed, *(boost::uint16_t*)ptr); + return seed; + } + +#else + + template <class T> + inline std::size_t float_hash_impl(T v) + { + int exp = 0; + + v = boost::hash_detail::call_frexp(v, &exp); + + // A postive value is easier to hash, so combine the + // sign with the exponent. + if(v < 0) { + v = -v; + exp += limits<T>::max_exponent - + limits<T>::min_exponent; + } + + // The result of frexp is always between 0.5 and 1, so its + // top bit will always be 1. Subtract by 0.5 to remove that. + v -= T(0.5); + v = boost::hash_detail::call_ldexp(v, + limits<std::size_t>::digits + 1); + std::size_t seed = static_cast<std::size_t>(v); + v -= seed; + + // ceiling(digits(T) * log2(radix(T))/ digits(size_t)) - 1; + std::size_t const length + = (limits<T>::digits * + boost::static_log2<limits<T>::radix>::value - 1) + / limits<std::size_t>::digits; + + for(std::size_t i = 0; i != length; ++i) + { + v = boost::hash_detail::call_ldexp(v, + limits<std::size_t>::digits); + std::size_t part = static_cast<std::size_t>(v); + v -= part; + hash_float_combine(seed, part); + } + + hash_float_combine(seed, exp); + + return seed; + } +#endif + + template <class T> + inline std::size_t float_hash_value(T v) + { +#if defined(BOOST_HASH_USE_FPCLASSIFY) + using namespace std; + switch (fpclassify(v)) { + case FP_ZERO: + return 0; + case FP_INFINITE: + return (std::size_t)(v > 0 ? -1 : -2); + case FP_NAN: + return (std::size_t)(-3); + case FP_NORMAL: + case FP_SUBNORMAL: + return float_hash_impl(v); + default: + BOOST_ASSERT(0); + return 0; + } +#else + return v == 0 ? 0 : float_hash_impl(v); +#endif + } + } +} + +#if defined(BOOST_MSVC) +#pragma warning(pop) +#endif + +#endif |