Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:13

0001 // Boost.Units - A C++ library for zero-overhead dimensional analysis and 
0002 // unit/quantity manipulation and conversion
0003 //
0004 // Copyright (C) 2003-2008 Matthias Christian Schabel
0005 // Copyright (C) 2008 Steven Watanabe
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See
0008 // accompanying file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_UNITS_CMATH_IMPL_HPP 
0012 #define BOOST_UNITS_CMATH_IMPL_HPP
0013 
0014 #include <boost/config.hpp>
0015 #include <boost/math/special_functions/fpclassify.hpp>
0016 
0017 namespace boost {
0018 namespace units {
0019 namespace detail {
0020 
0021 template<class Y> 
0022 inline bool isgreater BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
0023 {
0024     if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
0025     else return v1 > v2;
0026 }
0027 
0028 template<class Y> 
0029 inline bool isgreaterequal BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
0030 {
0031     if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
0032     else return v1 >= v2;
0033 }
0034 
0035 template<class Y> 
0036 inline bool isless BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
0037 {
0038     if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
0039     else return v1 < v2;
0040 }
0041 
0042 template<class Y> 
0043 inline bool islessequal BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
0044 {
0045     if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
0046     else return v1 <= v2;
0047 }
0048 
0049 template<class Y> 
0050 inline bool islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
0051 {
0052     if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
0053     else return v1 < v2 || v1 > v2;
0054 }
0055 
0056 template<class Y> 
0057 inline bool isunordered BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
0058 {
0059     return (boost::math::isnan)(v1) || (boost::math::isnan)(v2);
0060 }
0061 
0062 template<class Y>
0063 inline Y fdim BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
0064 {
0065     if((boost::math::isnan)(v1)) return v1;
0066     else if((boost::math::isnan)(v2)) return v2;
0067     else if(v1 > v2) return(v1 - v2);
0068     else return(Y(0));
0069 }
0070 
0071 #if 0
0072 
0073 template<class T>
0074 struct fma_issue_warning {
0075     enum { value = false };
0076 };
0077 
0078 template<class Y>
0079 inline Y fma(const Y& v1,const Y& v2,const Y& v3)
0080 {
0081     //this implementation does *not* meet the
0082     //requirement of infinite intermediate precision
0083     BOOST_STATIC_WARNING((fma_issue_warning<Y>::value));
0084 
0085     return v1 * v2 + v3;
0086 }
0087 
0088 #endif
0089 
0090 template<class Y>
0091 inline Y fmax BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
0092 {
0093     if((boost::math::isnan)(v1)) return(v2);
0094     else if((boost::math::isnan)(v2)) return(v1);
0095     else if(v1 > v2) return(v1);
0096     else return(v2);
0097 }
0098 
0099 template<class Y>
0100 inline Y fmin BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& v1,const Y& v2)
0101 {
0102     if((boost::math::isnan)(v1)) return(v2);
0103     else if((boost::math::isnan)(v2)) return(v1);
0104     else if(v1 < v2) return(v1);
0105     else return(v2);
0106 }
0107 
0108 //template<class Y>
0109 //inline long long llrint(const Y& val)
0110 //{
0111 //    return static_cast<long long>(rint(val));
0112 //}
0113 //
0114 //template<class Y>
0115 //inline long long llround(const Y& val)
0116 //{
0117 //    return static_cast<long long>(round(val));
0118 //}
0119 
0120 #if 0
0121 
0122 template<class Y>
0123 inline Y nearbyint(const Y& val)
0124 {
0125     //this is not really correct.
0126     //the result should be according to the
0127     //current rounding mode.
0128     using boost::math::round;
0129     return round(val);
0130 }
0131 
0132 template<class Y>
0133 inline Y rint(const Y& val)
0134 {
0135     //I don't feel like trying to figure out
0136     //how to raise a floating pointer exception
0137     return nearbyint(val);
0138 }
0139 
0140 #endif
0141 
0142 template<class Y>
0143 inline Y trunc BOOST_PREVENT_MACRO_SUBSTITUTION(const Y& val)
0144 {
0145     if(val > 0) return std::floor(val);
0146     else if(val < 0) return std::ceil(val);
0147     else return val;
0148 }
0149 
0150 }
0151 }
0152 }
0153 
0154 #endif // BOOST_UNITS_CMATH_IMPL_HPP