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
17namespace boost {
18namespace units {
19namespace detail {
20
21template<class Y>
22inline 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
28template<class Y>
29inline 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
35template<class Y>
36inline 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
42template<class Y>
43inline 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
49template<class Y>
50inline 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
56template<class Y>
57inline 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
62template<class Y>
63inline 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
73template<class T>
74struct fma_issue_warning {
75 enum { value = false };
76};
77
78template<class Y>
79inline 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
90template<class Y>
91inline 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
99template<class Y>
100inline 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
122template<class Y>
123inline 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
132template<class Y>
133inline 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
142template<class Y>
143inline 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
155

source code of boost/libs/units/include/boost/units/detail/cmath_impl.hpp