1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
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)
11 #ifndef BOOST_UNITS_CMATH_IMPL_HPP
12 #define BOOST_UNITS_CMATH_IMPL_HPP
14 #include <boost/config.hpp>
15 #include <boost/math/special_functions/fpclassify.hpp>
22 inline bool isgreater BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
24 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
29 inline bool isgreaterequal BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
31 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
36 inline bool isless BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
38 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
43 inline bool islessequal BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
45 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
50 inline bool islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
52 if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
53 else return v1 < v2 || v1 > v2;
57 inline bool isunordered BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
59 return (boost::math::isnan)(v1) || (boost::math::isnan)(v2);
63 inline Y fdim BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
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);
74 struct fma_issue_warning {
75 enum { value = false };
79 inline Y fma(const Y& v1,const Y& v2,const Y& v3)
81 //this implementation does *not* meet the
82 //requirement of infinite intermediate precision
83 BOOST_STATIC_WARNING((fma_issue_warning<Y>::value));
91 inline Y fmax BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
93 if((boost::math::isnan)(v1)) return(v2);
94 else if((boost::math::isnan)(v2)) return(v1);
95 else if(v1 > v2) return(v1);
100 inline Y fmin BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
102 if((boost::math::isnan)(v1)) return(v2);
103 else if((boost::math::isnan)(v2)) return(v1);
104 else if(v1 < v2) return(v1);
109 //inline long long llrint(const Y& val)
111 // return static_cast<long long>(rint(val));
115 //inline long long llround(const Y& val)
117 // return static_cast<long long>(round(val));
123 inline Y nearbyint(const Y& val)
125 //this is not really correct.
126 //the result should be according to the
127 //current rounding mode.
128 using boost::math::round;
133 inline Y rint(const Y& val)
135 //I don't feel like trying to figure out
136 //how to raise a floating pointer exception
137 return nearbyint(val);
143 inline Y trunc BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& val)
145 if(val > 0) return std::floor(val);
146 else if(val < 0) return std::ceil(val);
154 #endif // BOOST_UNITS_CMATH_IMPL_HPP