]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/units/detail/cmath_impl.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / units / detail / cmath_impl.hpp
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
3 //
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifndef BOOST_UNITS_CMATH_IMPL_HPP
12 #define BOOST_UNITS_CMATH_IMPL_HPP
13
14 #include <boost/config.hpp>
15 #include <boost/math/special_functions/fpclassify.hpp>
16
17 namespace boost {
18 namespace units {
19 namespace detail {
20
21 template<class Y>
22 inline bool isgreater BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
23 {
24 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
25 else return v1 > v2;
26 }
27
28 template<class Y>
29 inline bool isgreaterequal BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
30 {
31 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
32 else return v1 >= v2;
33 }
34
35 template<class Y>
36 inline bool isless BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
37 {
38 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
39 else return v1 < v2;
40 }
41
42 template<class Y>
43 inline bool islessequal BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
44 {
45 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
46 else return v1 <= v2;
47 }
48
49 template<class Y>
50 inline bool islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
51 {
52 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
53 else return v1 < v2 || v1 > v2;
54 }
55
56 template<class Y>
57 inline bool isunordered BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
58 {
59 return (boost::math::isnan)(v1) || (boost::math::isnan)(v2);
60 }
61
62 template<class Y>
63 inline Y fdim BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
64 {
65 if((boost::math::isnan)(v1)) return v1;
66 else if((boost::math::isnan)(v2)) return v2;
67 else if(v1 > v2) return(v1 - v2);
68 else return(Y(0));
69 }
70
71 #if 0
72
73 template<class T>
74 struct fma_issue_warning {
75 enum { value = false };
76 };
77
78 template<class Y>
79 inline Y fma(const Y& v1,const Y& v2,const Y& v3)
80 {
81 //this implementation does *not* meet the
82 //requirement of infinite intermediate precision
83 BOOST_STATIC_WARNING((fma_issue_warning<Y>::value));
84
85 return v1 * v2 + v3;
86 }
87
88 #endif
89
90 template<class Y>
91 inline Y fmax BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
92 {
93 if((boost::math::isnan)(v1)) return(v2);
94 else if((boost::math::isnan)(v2)) return(v1);
95 else if(v1 > v2) return(v1);
96 else return(v2);
97 }
98
99 template<class Y>
100 inline Y fmin BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
101 {
102 if((boost::math::isnan)(v1)) return(v2);
103 else if((boost::math::isnan)(v2)) return(v1);
104 else if(v1 < v2) return(v1);
105 else return(v2);
106 }
107
108 //template<class Y>
109 //inline long long llrint(const Y& val)
110 //{
111 // return static_cast<long long>(rint(val));
112 //}
113 //
114 //template<class Y>
115 //inline long long llround(const Y& val)
116 //{
117 // return static_cast<long long>(round(val));
118 //}
119
120 #if 0
121
122 template<class Y>
123 inline Y nearbyint(const Y& val)
124 {
125 //this is not really correct.
126 //the result should be according to the
127 //current rounding mode.
128 using boost::math::round;
129 return round(val);
130 }
131
132 template<class Y>
133 inline Y rint(const Y& val)
134 {
135 //I don't feel like trying to figure out
136 //how to raise a floating pointer exception
137 return nearbyint(val);
138 }
139
140 #endif
141
142 template<class Y>
143 inline Y trunc BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& val)
144 {
145 if(val > 0) return std::floor(val);
146 else if(val < 0) return std::ceil(val);
147 else return val;
148 }
149
150 }
151 }
152 }
153
154 #endif // BOOST_UNITS_CMATH_IMPL_HPP