made math functions inlnie

This commit is contained in:
Juan Linietsky 2017-01-12 08:55:19 -03:00
parent 942a9d9a20
commit ad224295c0
2 changed files with 119 additions and 131 deletions

View file

@ -29,7 +29,7 @@
#include "math_funcs.h" #include "math_funcs.h"
#include "core/os/os.h" #include "core/os/os.h"
#include <math.h>
#include "float.h" #include "float.h"
uint32_t Math::default_seed=1; uint32_t Math::default_seed=1;
@ -69,48 +69,6 @@ double Math::randf() {
return (double)rand() / (double)Math::RANDOM_MAX; 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) { 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) { double Math::dectime(double p_value,double p_amount, double p_step) {
float sgn = p_value < 0 ? -1.0 : 1.0; 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; 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) { int Math::step_decimals(double p_step) {
@ -244,20 +150,7 @@ double Math::stepify(double p_value,double p_step) {
return p_value; 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) { uint32_t Math::larger_prime(uint32_t p_val) {

View file

@ -33,38 +33,125 @@
#include "math_defs.h" #include "math_defs.h"
#ifndef NO_MATH_H #ifndef NO_MATH_H
#include "math.h" #include <math.h>
#endif #endif
#define Math_PI 3.14159265358979323846
#define Math_SQRT12 0.7071067811865475244008443621048490
class Math { class Math {
static uint32_t default_seed; static uint32_t default_seed;
public: public:
Math() {}; // useless to instance Math() {} // useless to instance
enum { enum {
RANDOM_MAX=2147483647L RANDOM_MAX=2147483647L
}; };
static double sin(double p_x);
static double cos(double p_x); static _ALWAYS_INLINE_ double sin(double p_x) {
static double tan(double p_x);
static double sinh(double p_x); return ::sin(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 _ALWAYS_INLINE_ double cos(double p_x) {
static double atan(double p_x);
static double atan2(double p_y, double p_x); return ::cos(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 _ALWAYS_INLINE_ double tan(double p_x) {
static double fposmod(double p_x,double p_y);
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 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 double ease(double p_x, double p_c);
static int step_decimals(double p_step); static int step_decimals(double p_step);
static double stepify(double p_value,double p_step); static double stepify(double p_value,double p_step);
@ -84,10 +171,20 @@ public:
return Math::exp( p_db * 0.11512925464970228420089957273422 ); return Math::exp( p_db * 0.11512925464970228420089957273422 );
} }
static bool is_nan(double p_val); static _ALWAYS_INLINE_ bool is_nan(double p_val) {
static bool is_inf(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 uint32_t rand();
static double randf(); static double randf();
@ -289,7 +386,5 @@ public:
}; };
#define Math_PI 3.14159265358979323846
#define Math_SQRT12 0.7071067811865475244008443621048490
#endif // MATH_FUNCS_H #endif // MATH_FUNCS_H