1 /* Copyright (C) 2008 Tobi Vollebregt */ 2 3 /* Conditionally include streflop depending on STREFLOP_* #defines: 4 If one of those is present, #include "streflop.h", otherwise #include <math.h> 5 6 When faced with ambiguous call errors with e.g. fabs, use math::function. 7 Add it to math namespace if it doesn't exist there yet. */ 8 9 #ifndef STREFLOP_COND_H 10 #define STREFLOP_COND_H 11 12 #if (defined(STREFLOP_X87) || defined(STREFLOP_SSE) || defined(STREFLOP_SOFT)) && (!defined(NOT_USING_STREFLOP)) 13 #include "streflop.h" 14 namespace math { 15 using namespace streflop; 16 } 17 #else 18 #include <cmath> 19 20 #ifdef __APPLE__ 21 // macosx's cmath doesn't include c++11's std::hypot yet (tested 2013) 22 namespace std { 23 template<typename T> T hypot(T x, T y); 24 } 25 #endif 26 27 28 namespace math { 29 using std::fabs; 30 // We are using fastmath::sqrt_sse instead! 31 // using std::sqrt; 32 using std::sin; 33 using std::cos; 34 35 using std::sinh; 36 using std::cosh; 37 using std::tan; 38 using std::tanh; 39 using std::asin; 40 using std::acos; 41 using std::atan; 42 using std::atan2; 43 44 using std::ceil; 45 using std::floor; 46 using std::fmod; 47 using std::hypot; 48 using std::pow; 49 using std::log; 50 using std::log10; 51 using std::exp; 52 using std::frexp; 53 using std::ldexp; 54 // the following are C99 functions -> not supported by VS C 55 #if !defined(_MSC_VER) || _MSC_VER < 1500 56 using std::isnan; 57 using std::isinf; 58 using std::isfinite; 59 60 #elif __cplusplus isnan(T value)61 template<typename T> inline bool isnan(T value) { 62 return value != value; 63 } 64 // requires include <limits> isinf(T value)65 template<typename T> inline bool isinf(T value) { 66 return std::numeric_limits<T>::has_infinity && value == std::numeric_limits<T>::infinity(); 67 } 68 // requires include <limits> isfinite(T value)69 template<typename T> inline bool isfinite(T value) { 70 return !isinf<T>(value); 71 } 72 #endif 73 } 74 75 76 #ifdef __APPLE__ 77 // see above 78 79 #include <algorithm> 80 81 namespace std { 82 template<typename T> hypot(T x,T y)83 T hypot(T x, T y) { 84 x = std::abs(x); 85 y = std::abs(y); 86 auto t = std::min(x,y); 87 x = std::max(x,y); 88 t = t / x; 89 return x * sqrtf(1.f + t*t); 90 } 91 } 92 #endif 93 94 #endif 95 96 #endif // STREFLOP_COND_H 97