diff --git a/third_party/ObjexxFCL/src/ObjexxFCL/Fmath.hh b/third_party/ObjexxFCL/src/ObjexxFCL/Fmath.hh index ffd7922b8ee..d8854cc4bf2 100644 --- a/third_party/ObjexxFCL/src/ObjexxFCL/Fmath.hh +++ b/third_party/ObjexxFCL/src/ObjexxFCL/Fmath.hh @@ -27,92 +27,175 @@ namespace ObjexxFCL { +// this file contains the changes for function approximation: +// power function, and min/max typedef std::intmax_t SSize; +/* +float myxor(float x, float y) +{ + unsigned long long* xPtr = (unsigned long long*)&x; + unsigned long long* yPtr = (unsigned long long*)&y; + unsigned long long uXor = (*xPtr) ^ (*yPtr); + float dXor = *((float*)&uXor); + return dXor; +}*/ + // min ///// // min( short, short ) -inline + + inline short int min( short int const a, short int const b ) { - return ( a < b ? a : b ); + // return ( b ^ ((a ^ b) & -(a < b)) ); + return a*(a @@ -128,8 +211,13 @@ inline int min( int const a, int const b, int const c ) { - return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) ); + return ( min(a, min(b,c)) ); } +/* +int min(int x, int y, int z) +{ + return min(x, min(y,z)); +}*/ // min( int, int, int, int, ... ) template< typename... Ts > @@ -145,8 +233,13 @@ inline long int min( long int const a, long int const b, long int const c ) { - return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) ); + return ( min(a, min(b,c)) ); } +/* +long int min(long int const x, long int const y, long int const z) +{ + return min(x, min(y,z)); +}*/ // min( long, long, long, long, ... ) template< typename... Ts > @@ -162,9 +255,15 @@ inline unsigned short int min( unsigned short int const a, unsigned short int const b, unsigned short int const c ) { - return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) ); + return ( min(a, min(b,c))); } +/* +unsigned short int min(unsigned short int const x, unsigned short int const y, unsigned short int const z) +{ + return min(x, min(y,z)); +}*/ + // min( unsigned short, unsigned short, unsigned short, unsigned short, ... ) template< typename... Ts > inline @@ -179,8 +278,16 @@ inline unsigned int min( unsigned int const a, unsigned int const b, unsigned int const c ) { - return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) ); + //return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) ); + return min(min(a,b),c); +} + +/* +unsigned int min(unsigned int const x, unsigned int const y) +{ + return y ^ ((x ^ y) & -(x < y)); } +*/ // min( unsigned, unsigned, unsigned, unsigned, ... ) template< typename... Ts > @@ -196,8 +303,13 @@ inline unsigned long int min( unsigned long int const a, unsigned long int const b, unsigned long int const c ) { - return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) ); + return (min(a,min(b,c))); } +/* +unsigned long int min(unsigned long int const x, unsigned long int const y, unsigned long int const z) +{ + return min(x,min(y,z)); +}*/ // min( unsigned long, unsigned long, unsigned long, unsigned long, ... ) template< typename... Ts > @@ -213,8 +325,13 @@ inline float min( float const a, float const b, float const c ) { - return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) ); + return ( min(a, min(b,c)) ); } +/* +float min(float const x, float const y, float const z) +{ + return min(x,min(y,z)); +}*/ // min( float, float, float, float, ... ) template< typename... Ts > @@ -230,8 +347,13 @@ inline double min( double const a, double const b, double const c ) { - return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) ); + return ( min(a, min(b,c)) ); } +/* +double min(double const x, double const y, double const z) +{ + return min(x,min(y,z)); +}*/ // min( double, double, double, double, ... ) template< typename... Ts > @@ -247,8 +369,14 @@ inline long double min( long double const a, long double const b, long double const c ) { - return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) ); + return ( min(a, min(b,c)) ); } +/* +long double min(long double const x, long double const y, long double const z) +{ + return min(x, min(y,z)); +}*/ + // min( long double, long double, long double, long double, ... ) template< typename... Ts > @@ -284,72 +412,138 @@ inline short int max( short int const a, short int const b ) { - return ( a < b ? b : a ); + //return ( a ^ ((a ^ b) & -(a < b)) ); + return b*(a inline @@ -376,8 +577,14 @@ inline int max( int const a, int const b, int const c ) { - return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + return ( max(a, max(b,c)) ); } +/* +int max( int const x, int const y, int const z) +{ + return max(x,max(y,z)); +}*/ + // max( int, int, int, int, ... ) template< typename... Ts > @@ -393,9 +600,16 @@ inline long int max( long int const a, long int const b, long int const c ) { - return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + return ( max(a, max(b,c)) ); } +/* +long int max(long int const x, long int const y, long int const z) +{ + return max(x,max(y,z)); +}*/ + + // max( long, long, long, long, ... ) template< typename... Ts > inline @@ -410,8 +624,13 @@ inline unsigned short int max( unsigned short int const a, unsigned short int const b, unsigned short int const c ) { - return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + return ( max(a, max(b,c)) ); } +/* +unsigned short int max(unsigned short int const x, unsigned short int const y, unsigned short int const z) +{ + return max(x,max(y,z)); +}*/ // max( unsigned short, unsigned short, unsigned short, unsigned short, ... ) template< typename... Ts > @@ -423,12 +642,18 @@ max( unsigned short int const a, unsigned short int const b, unsigned short int } // max( unsigned, unsigned, unsigned ) -inline + inline unsigned int max( unsigned int const a, unsigned int const b, unsigned int const c ) { - return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + return ( max(a, max(b,c)) ); } +/* +unsigned int max(unsigned int const x, unsigned int const y, unsigned int const z) +{ + return max(x,max(y,z)); +}*/ + // max( unsigned, unsigned, unsigned, unsigned, ... ) template< typename... Ts > @@ -440,12 +665,18 @@ max( unsigned int const a, unsigned int const b, unsigned int const c, unsigned } // max( unsigned long, unsigned long, unsigned long ) -inline + inline unsigned long int max( unsigned long int const a, unsigned long int const b, unsigned long int const c ) { - return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + return ( max(a, max(b,c)) ); +} +/* +unsigned long int max(unsigned long int const x, unsigned long int const y, unsigned long int const z) +{ + return max(x,max(y,z)); } +*/ // max( unsigned long, unsigned long, unsigned long, unsigned long, ... ) template< typename... Ts > @@ -457,12 +688,18 @@ max( unsigned long int const a, unsigned long int const b, unsigned long int con } // max( float, float, float ) -inline + inline float max( float const a, float const b, float const c ) { - return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + //return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + return max(max(a,b),c); } +/* +float max(float const x, float const y, float const z) +{ + return max(x,max(y,z)); +}*/ // max( float, float, float, float, ... ) template< typename... Ts > @@ -474,13 +711,21 @@ max( float const a, float const b, float const c, float const d, Ts const &... o } // max( double, double, double ) -inline + inline double max( double const a, double const b, double const c ) { - return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + //return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + return max(max(a,b),c) } +/* +double max(double const x, double const y, double const z) +{ + return max(x,max(y,z)); +}*/ + + // max( double, double, double, double, ... ) template< typename... Ts > inline @@ -491,13 +736,23 @@ max( double const a, double const b, double const c, double const d, Ts const &. } // max( long double, long double, long double ) + inline long double max( long double const a, long double const b, long double const c ) { - return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + //return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + return max(max(a,b),c) } + +/* +long double max(long double const x, long double const y, long double const z) +{ + return max(x,max(y,z)); +}*/ + + // max( long double, long double, long double, long double, ... ) template< typename... Ts > inline @@ -513,9 +768,12 @@ inline T const & max( T const & a, T const & b, T const & c ) { - return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + //return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) ); + return max(max(a,b),c) } + + // max( a, b, c, d, ... ) template< typename T, typename... Ts > inline @@ -1085,65 +1343,108 @@ pow_2( T const x ) { return x * x; } - +/* +double pow_2(double x) +{ + return exp(2*log(x)); +} + */ // pow_3( x ) == x^3 -template< typename T, class = typename std::enable_if< std::is_arithmetic< T >::value >::type > + + template< typename T, class = typename std::enable_if< std::is_arithmetic< T >::value >::type > inline T pow_3( T const x ) { - return x * x * x; + //return x * x * x; + return exp(3*log(x)); } +/* +double pow_3(double x) +{ + return exp(3*log(x)); + +}*/ + +//// pow_4( x ) == x^4 -// pow_4( x ) == x^4 template< typename T, class = typename std::enable_if< std::is_arithmetic< T >::value >::type > inline T pow_4( T const x ) { - T const t( x * x ); - return t * t; + //T const t( x * x ); + //return t * t; + return exp(4*log(x)); +} + +/* +double pow_4 (double x) +{ + return exp(4*log(x)); } +*/ // pow_5( x ) == x^5 -template< typename T, class = typename std::enable_if< std::is_arithmetic< T >::value >::type > + + template< typename T, class = typename std::enable_if< std::is_arithmetic< T >::value >::type > inline T pow_5( T const x ) { - T const t( x * x ); - return t * t * x; + //T const t( x * x ); + //return t * t * x; + return exp(5*log(x)); } + // pow_6( x ) == x^6 template< typename T, class = typename std::enable_if< std::is_arithmetic< T >::value >::type > inline T pow_6( T const x ) { - T const t( x * x * x ); - return t * t; + //T const t( x * x * x ); + //return t * t; + return exp(6*log(x)); + } +/* +double pow_6(float x) +{ + return exp(6*log(x)); + +}*/ + // pow_7( x ) == x^7 + template< typename T, class = typename std::enable_if< std::is_arithmetic< T >::value >::type > inline T pow_7( T const x ) { - T const t( x * x * x ); - return t * t * x; -} - + //T const t( x * x * x ); + //return t * t * x; + return exp(7*log(x)); +} + +/* + double pow_7(float x) + { + return exp(7*log(x)); + } +*/ // pow_8( x ) == x^8 template< typename T, class = typename std::enable_if< std::is_arithmetic< T >::value >::type > inline T pow_8( T const x ) { - T t( x * x ); - t *= t; - return t * t; + //T t( x * x ); + //t *= t; + //return t * t; + return exp(8*log(x)); } // pow_9( x ) == x^9 @@ -1152,10 +1453,13 @@ inline T pow_9( T const x ) { - T const t( x * x * x ); - return t * t * t; + //T const t( x * x * x ); + //return t * t * t; + return exp(9*log(x)); } + + // root_4( x ) == x^(1/4) template< typename T, class = typename std::enable_if< std::is_arithmetic< T >::value >::type > inline @@ -1208,8 +1512,14 @@ inline T pow_2( T const & x ) { - return x * x; + return exp(2*log(x)); } +/* +double pow_2 (double x) +{ + + return exp(2*log(x)); +}*/ // pow_3( x ) == x^3 template< typename T, class = typename std::enable_if< ! std::is_arithmetic< T >::value >::type > @@ -1217,18 +1527,31 @@ inline T pow_3( T const & x ) { - return x * x * x; + return exp(3*log(x)); } +/* +double pow_3 (double x) +{ + + return exp(3*log(x)); +}*/ // pow_4( x ) == x^4 + template< typename T, class = typename std::enable_if< ! std::is_arithmetic< T >::value >::type > inline T pow_4( T const & x ) { - T const t( x * x ); - return t * t; + //T const t( x * x ); + return pow_2(pow_2(x)); } + /* +double pow_4 (double x) +{ + + return exp(4*log(x)); +}*/ // pow_5( x ) == x^5 template< typename T, class = typename std::enable_if< ! std::is_arithmetic< T >::value >::type > @@ -1236,9 +1559,16 @@ inline T pow_5( T const & x ) { - T const t( x * x ); - return t * t * x; + //T const t( x * x ); + //return t * t * x; + return pow_2(x)*pow_3(x); } +/* +double pow_5(double x) +{ + return exp(5*log(x)); + +}*/ // pow_6( x ) == x^6 template< typename T, class = typename std::enable_if< ! std::is_arithmetic< T >::value >::type > @@ -1246,19 +1576,34 @@ inline T pow_6( T const & x ) { - T const t( x * x * x ); - return t * t; + //T const t( x * x * x ); + //return t * t; + return pow_2(pow_3(x)); } + /* +double pow_6(double x) +{ + return exp(6*log(x)); + +}*/ // pow_7( x ) == x^7 + template< typename T, class = typename std::enable_if< ! std::is_arithmetic< T >::value >::type > inline T pow_7( T const & x ) { - T const t( x * x * x ); - return t * t * x; + //T const t( x * x * x ); + //return t * t * x; + return pow_3(x)*pow_4(x); } +/* +double pow_7(double x) +{ + return exp(7*log(x)); + +}*/ // pow_8( x ) == x^8 template< typename T, class = typename std::enable_if< ! std::is_arithmetic< T >::value >::type > @@ -1266,10 +1611,17 @@ inline T pow_8( T const & x ) { - T t( x * x ); - t *= t; - return t * t; + //T t( x * x ); + //t *= t; + //return t * t; + return pow_4(x)*pow_4(x); } + /* +double pow_8(double x) +{ + return exp(8*log(x)); + +}*/ // pow_9( x ) == x^9 template< typename T, class = typename std::enable_if< ! std::is_arithmetic< T >::value >::type > @@ -1277,9 +1629,17 @@ inline T pow_9( T const & x ) { - T const t( x * x * x ); - return t * t * t; + //T const t( x * x * x ); + //return t * t * t; + return pow_4(x)*pow_5(x); } + /* + +double pow_9(double x) +{ + return exp(9*log(x)); + +}*/ // Tolerant Comparisons ///// @@ -1346,3 +1706,4 @@ gt_tol( T const & x, T const & y, T const & r_tol, T const & a_tol = T( 0 ) ) } // ObjexxFCL #endif // ObjexxFCL_Fmath_hh_INCLUDED +