From ad224295c0a24a0588351c4ab750e43867bcdde9 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 12 Jan 2017 08:55:19 -0300 Subject: [PATCH] made math functions inlnie --- core/math/math_funcs.cpp | 109 +----------------------------- core/math/math_funcs.h | 141 ++++++++++++++++++++++++++++++++------- 2 files changed, 119 insertions(+), 131 deletions(-) diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index db1c52ccb43..8353aa0ebe1 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -29,7 +29,7 @@ #include "math_funcs.h" #include "core/os/os.h" -#include + #include "float.h" uint32_t Math::default_seed=1; @@ -69,48 +69,6 @@ double Math::randf() { return (double)rand() / (double)Math::RANDOM_MAX; } -double Math::sin(double p_x) { - - return ::sin(p_x); - -} - -double Math::cos(double p_x) { - - return ::cos(p_x); - -} - -double Math::tan(double p_x) { - - return ::tan(p_x); - -} -double Math::sinh(double p_x) { - - return ::sinh(p_x); -} - -double Math::cosh(double p_x) { - - return ::cosh(p_x); -} - -double Math::tanh(double p_x) { - - return ::tanh(p_x); -} - - -double Math::deg2rad(double p_y) { - - return p_y*Math_PI/180.0; -} - -double Math::rad2deg(double p_y) { - - return p_y*180.0/Math_PI; -} double Math::round(double p_val) { @@ -122,22 +80,6 @@ double Math::round(double p_val) { } } -double Math::asin(double p_x) { - - return ::asin(p_x); - -} - -double Math::acos(double p_x) { - - return ::acos(p_x); -} - -double Math::atan(double p_x) { - - return ::atan(p_x); -} - double Math::dectime(double p_value,double p_amount, double p_step) { float sgn = p_value < 0 ? -1.0 : 1.0; @@ -148,42 +90,6 @@ double Math::dectime(double p_value,double p_amount, double p_step) { return val*sgn; } -double Math::atan2(double p_y, double p_x) { - - return ::atan2(p_y,p_x); - -} -double Math::sqrt(double p_x) { - - return ::sqrt(p_x); -} - -double Math::fmod(double p_x,double p_y) { - - return ::fmod(p_x,p_y); -} - -double Math::fposmod(double p_x,double p_y) { - - if (p_x>=0) { - - return Math::fmod(p_x,p_y); - - } else { - - return p_y-Math::fmod(-p_x,p_y); - } - -} -double Math::floor(double p_x) { - - return ::floor(p_x); -} - -double Math::ceil(double p_x) { - - return ::ceil(p_x); -} int Math::step_decimals(double p_step) { @@ -244,20 +150,7 @@ double Math::stepify(double p_value,double p_step) { return p_value; } -bool Math::is_nan(double p_val) { - return (p_val!=p_val); -} - -bool Math::is_inf(double p_val) { - -#ifdef _MSC_VER - return !_finite(p_val); -#else - return isinf(p_val); -#endif - -} uint32_t Math::larger_prime(uint32_t p_val) { diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 24081528f0e..8ce59224ff4 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -33,38 +33,125 @@ #include "math_defs.h" #ifndef NO_MATH_H -#include "math.h" +#include #endif +#define Math_PI 3.14159265358979323846 +#define Math_SQRT12 0.7071067811865475244008443621048490 + class Math { static uint32_t default_seed; public: - Math() {}; // useless to instance + Math() {} // useless to instance enum { RANDOM_MAX=2147483647L }; - static double sin(double p_x); - static double cos(double p_x); - static double tan(double p_x); - static double sinh(double p_x); - static double cosh(double p_x); - static double tanh(double p_x); - static double asin(double p_x); - static double acos(double p_x); - static double atan(double p_x); - static double atan2(double p_y, double p_x); - static double deg2rad(double p_y); - static double rad2deg(double p_y); - static double sqrt(double p_x); - static double fmod(double p_x,double p_y); - static double fposmod(double p_x,double p_y); + + static _ALWAYS_INLINE_ double sin(double p_x) { + + return ::sin(p_x); + + } + + static _ALWAYS_INLINE_ double cos(double p_x) { + + return ::cos(p_x); + + } + + static _ALWAYS_INLINE_ double tan(double p_x) { + + return ::tan(p_x); + + } + static _ALWAYS_INLINE_ double sinh(double p_x) { + + return ::sinh(p_x); + } + + static _ALWAYS_INLINE_ double cosh(double p_x) { + + return ::cosh(p_x); + } + + static _ALWAYS_INLINE_ double tanh(double p_x) { + + return ::tanh(p_x); + } + + + static _ALWAYS_INLINE_ double asin(double p_x) { + + return ::asin(p_x); + + } + + static _ALWAYS_INLINE_ double acos(double p_x) { + + return ::acos(p_x); + } + + static _ALWAYS_INLINE_ double atan(double p_x) { + + return ::atan(p_x); + } + + static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { + + return ::atan2(p_y,p_x); + + } + + static _ALWAYS_INLINE_ double deg2rad(double p_y) { + + return p_y*Math_PI/180.0; + } + + static _ALWAYS_INLINE_ double rad2deg(double p_y) { + + return p_y*180.0/Math_PI; + } + + + static _ALWAYS_INLINE_ double sqrt(double p_x) { + + return ::sqrt(p_x); + } + + static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) { + + return ::fmod(p_x,p_y); + } + + static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) { + + if (p_x>=0) { + + return fmod(p_x,p_y); + + } else { + + return p_y-fmod(-p_x,p_y); + } + + } + static _ALWAYS_INLINE_ double floor(double p_x) { + + return ::floor(p_x); + } + + static _ALWAYS_INLINE_ double ceil(double p_x) { + + return ::ceil(p_x); + } + + static uint32_t rand_from_seed(uint32_t *seed); - static double floor(double p_x); - static double ceil(double p_x); + static double ease(double p_x, double p_c); static int step_decimals(double p_step); static double stepify(double p_value,double p_step); @@ -84,10 +171,20 @@ public: return Math::exp( p_db * 0.11512925464970228420089957273422 ); } - static bool is_nan(double p_val); - static bool is_inf(double p_val); + static _ALWAYS_INLINE_ bool is_nan(double p_val) { + return (p_val!=p_val); + } + static _ALWAYS_INLINE_ bool is_inf(double p_val) { + + #ifdef _MSC_VER + return !_finite(p_val); + #else + return isinf(p_val); + #endif + + } static uint32_t rand(); static double randf(); @@ -289,7 +386,5 @@ public: }; -#define Math_PI 3.14159265358979323846 -#define Math_SQRT12 0.7071067811865475244008443621048490 #endif // MATH_FUNCS_H