Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3 Copyright (c) 2001-2011 Hartmut Kaiser
|
Chris@16
|
4 http://spirit.sourceforge.net/
|
Chris@16
|
5
|
Chris@16
|
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 =============================================================================*/
|
Chris@16
|
9 #if !defined(SPIRIT_SIGN_MAR_11_2009_0734PM)
|
Chris@16
|
10 #define SPIRIT_SIGN_MAR_11_2009_0734PM
|
Chris@16
|
11
|
Chris@16
|
12 #if defined(_MSC_VER)
|
Chris@16
|
13 #pragma once
|
Chris@16
|
14 #endif
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/config/no_tr1/cmath.hpp>
|
Chris@16
|
17 #include <boost/version.hpp>
|
Chris@16
|
18 #if BOOST_VERSION < 104000
|
Chris@16
|
19 #include <boost/spirit/home/support/detail/math/fpclassify.hpp>
|
Chris@16
|
20 #include <boost/spirit/home/support/detail/math/signbit.hpp>
|
Chris@16
|
21 #else
|
Chris@16
|
22 #include <boost/math/special_functions/fpclassify.hpp>
|
Chris@16
|
23 #include <boost/math/special_functions/sign.hpp>
|
Chris@16
|
24 #endif
|
Chris@16
|
25
|
Chris@16
|
26 namespace boost { namespace spirit { namespace detail
|
Chris@16
|
27 {
|
Chris@16
|
28 #if BOOST_VERSION < 104000
|
Chris@16
|
29 // signbit(-NAN) is broken for versions of Boost earlier than 1.40.0
|
Chris@16
|
30 // This routine has been taken and adapted from Johan Rade's fp_traits
|
Chris@16
|
31 // library
|
Chris@16
|
32 template<typename T>
|
Chris@16
|
33 inline bool (signbit)(T x)
|
Chris@16
|
34 {
|
Chris@16
|
35 return (boost::spirit::math::signbit)(x);
|
Chris@16
|
36 }
|
Chris@16
|
37
|
Chris@16
|
38 template<typename T>
|
Chris@16
|
39 inline T (changesign)(T x)
|
Chris@16
|
40 {
|
Chris@16
|
41 return (boost::spirit::math::changesign)(x);
|
Chris@16
|
42 }
|
Chris@16
|
43 #else
|
Chris@16
|
44 template<typename T>
|
Chris@16
|
45 inline bool (signbit)(T x)
|
Chris@16
|
46 {
|
Chris@16
|
47 return (boost::math::signbit)(x) ? true : false;
|
Chris@16
|
48 }
|
Chris@16
|
49
|
Chris@16
|
50 // This routine has been taken and adapted from Johan Rade's fp_traits
|
Chris@16
|
51 // library
|
Chris@16
|
52 template<typename T>
|
Chris@16
|
53 inline T (changesign)(T x)
|
Chris@16
|
54 {
|
Chris@16
|
55 #if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && !defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY)
|
Chris@16
|
56 return -x;
|
Chris@16
|
57 #else
|
Chris@16
|
58 typedef typename math::detail::fp_traits<T>::type traits_type;
|
Chris@16
|
59
|
Chris@16
|
60 typename traits_type::bits a;
|
Chris@16
|
61 traits_type::get_bits(x, a);
|
Chris@16
|
62 a ^= traits_type::sign;
|
Chris@16
|
63 traits_type::set_bits(x, a);
|
Chris@16
|
64 return x;
|
Chris@16
|
65 #endif
|
Chris@16
|
66 }
|
Chris@16
|
67 #endif
|
Chris@16
|
68
|
Chris@16
|
69 }}}
|
Chris@16
|
70
|
Chris@16
|
71 #endif
|