comparison DEPENDENCIES/generic/include/boost/math/special_functions/sign.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
29 { 29 {
30 return (std::signbit)(x); 30 return (std::signbit)(x);
31 } 31 }
32 #endif 32 #endif
33 33
34 template<class T> 34 // Generic versions first, note that these do not handle
35 // signed zero or NaN.
36
37 template<class T>
35 inline int signbit_impl(T x, generic_tag<true> const&) 38 inline int signbit_impl(T x, generic_tag<true> const&)
36 { 39 {
37 return x < 0; 40 return x < 0;
38 } 41 }
39 42
41 inline int signbit_impl(T x, generic_tag<false> const&) 44 inline int signbit_impl(T x, generic_tag<false> const&)
42 { 45 {
43 return x < 0; 46 return x < 0;
44 } 47 }
45 48
46 template<class T> 49 #if defined(__GNUC__) && (LDBL_MANT_DIG == 106)
50 //
51 // Special handling for GCC's "double double" type,
52 // in this case the sign is the same as the sign we
53 // get by casting to double, no overflow/underflow
54 // can occur since the exponents are the same magnitude
55 // for the two types:
56 //
57 inline int signbit_impl(long double x, generic_tag<true> const&)
58 {
59 return (boost::math::signbit)(static_cast<double>(x));
60 }
61 inline int signbit_impl(long double x, generic_tag<false> const&)
62 {
63 return (boost::math::signbit)(static_cast<double>(x));
64 }
65 #endif
66
67 template<class T>
47 inline int signbit_impl(T x, ieee_copy_all_bits_tag const&) 68 inline int signbit_impl(T x, ieee_copy_all_bits_tag const&)
48 { 69 {
49 typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; 70 typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits;
50 71
51 BOOST_DEDUCED_TYPENAME traits::bits a; 72 BOOST_DEDUCED_TYPENAME traits::bits a;
63 84
64 return a & traits::sign ? 1 : 0; 85 return a & traits::sign ? 1 : 0;
65 } 86 }
66 87
67 // Changesign 88 // Changesign
89
90 // Generic versions first, note that these do not handle
91 // signed zero or NaN.
68 92
69 template<class T> 93 template<class T>
70 inline T (changesign_impl)(T x, generic_tag<true> const&) 94 inline T (changesign_impl)(T x, generic_tag<true> const&)
71 { 95 {
72 return -x; 96 return -x;
75 template<class T> 99 template<class T>
76 inline T (changesign_impl)(T x, generic_tag<false> const&) 100 inline T (changesign_impl)(T x, generic_tag<false> const&)
77 { 101 {
78 return -x; 102 return -x;
79 } 103 }
80 104 #if defined(__GNUC__) && (LDBL_MANT_DIG == 106)
105 //
106 // Special handling for GCC's "double double" type,
107 // in this case we need to change the sign of both
108 // components of the "double double":
109 //
110 inline long double (changesign_impl)(long double x, generic_tag<true> const&)
111 {
112 double* pd = reinterpret_cast<double*>(&x);
113 pd[0] = boost::math::changesign(pd[0]);
114 pd[1] = boost::math::changesign(pd[1]);
115 return x;
116 }
117 inline long double (changesign_impl)(long double x, generic_tag<false> const&)
118 {
119 double* pd = reinterpret_cast<double*>(&x);
120 pd[0] = boost::math::changesign(pd[0]);
121 pd[1] = boost::math::changesign(pd[1]);
122 return x;
123 }
124 #endif
81 125
82 template<class T> 126 template<class T>
83 inline T changesign_impl(T x, ieee_copy_all_bits_tag const&) 127 inline T changesign_impl(T x, ieee_copy_all_bits_tag const&)
84 { 128 {
85 typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::sign_change_type traits; 129 typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::sign_change_type traits;