summaryrefslogtreecommitdiffstats
path: root/core/math/math_funcs.cpp
diff options
context:
space:
mode:
authorFerenc Arn <tagcup@yahoo.com>2017-01-14 14:35:39 -0600
committerFerenc Arn <tagcup@yahoo.com>2017-01-16 13:36:33 -0600
commit6f4f9aa6ded6da027c84cc466c767334dc3d3362 (patch)
tree4d45d7e600a069d7feb2a2dae3a70d6b9ddbf884 /core/math/math_funcs.cpp
parentd13f2f9e25e380496e706b59720cd85eed299ca2 (diff)
downloadredot-engine-6f4f9aa6ded6da027c84cc466c767334dc3d3362.tar.gz
Overloaded basic math funcs (double and float variants). Use real_t rather than float or double in generic functions (core/math) whenever possible.
Also inlined some more math functions.
Diffstat (limited to 'core/math/math_funcs.cpp')
-rw-r--r--core/math/math_funcs.cpp60
1 files changed, 15 insertions, 45 deletions
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index ef8c1ec539..e079f9c5f7 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -63,35 +63,8 @@ uint32_t Math::rand() {
return pcg32_random_r(&default_pcg);
}
-double Math::randf() {
-
- return (double)rand() / (double)Math::RANDOM_MAX;
-}
-
-
-double Math::round(double p_val) {
-
- if (p_val>=0) {
- return ::floor(p_val+0.5);
- } else {
- p_val=-p_val;
- return -::floor(p_val+0.5);
- }
-}
-
-double Math::dectime(double p_value,double p_amount, double p_step) {
-
- float sgn = p_value < 0 ? -1.0 : 1.0;
- float val = absf(p_value);
- val-=p_amount*p_step;
- if (val<0.0)
- val=0.0;
- return val*sgn;
-}
-
int Math::step_decimals(double p_step) {
-
static const int maxn=9;
static const double sd[maxn]={
0.9999, // somehow compensate for floating point error
@@ -105,7 +78,7 @@ int Math::step_decimals(double p_step) {
0.000000009999
};
- double as=absf(p_step);
+ double as=Math::abs(p_step);
for(int i=0;i<maxn;i++) {
if (as>=sd[i]) {
return i;
@@ -115,8 +88,16 @@ int Math::step_decimals(double p_step) {
return maxn;
}
-double Math::ease(double p_x, double p_c) {
+double Math::dectime(double p_value,double p_amount, double p_step) {
+ double sgn = p_value < 0 ? -1.0 : 1.0;
+ double val = Math::abs(p_value);
+ val-=p_amount*p_step;
+ if (val<0.0)
+ val=0.0;
+ return val*sgn;
+}
+double Math::ease(double p_x, double p_c) {
if (p_x<0)
p_x=0;
else if (p_x>1.0)
@@ -137,20 +118,16 @@ double Math::ease(double p_x, double p_c) {
}
} else
return 0; // no ease (raw)
-
}
double Math::stepify(double p_value,double p_step) {
-
if (p_step!=0) {
-
- p_value=floor( p_value / p_step + 0.5 ) * p_step;
+ p_value=Math::floor( p_value / p_step + 0.5 ) * p_step;
}
return p_value;
}
-
uint32_t Math::larger_prime(uint32_t p_val) {
static const uint32_t primes[] = {
@@ -199,22 +176,15 @@ uint32_t Math::larger_prime(uint32_t p_val) {
}
double Math::random(double from, double to) {
-
unsigned int r = Math::rand();
double ret = (double)r/(double)RANDOM_MAX;
return (ret)*(to-from) + from;
}
-double Math::pow(double x, double y) {
-
- return ::pow(x,y);
+float Math::random(float from, float to) {
+ unsigned int r = Math::rand();
+ float ret = (float)r/(float)RANDOM_MAX;
+ return (ret)*(to-from) + from;
}
-double Math::log(double x) {
-
- return ::log(x);
-}
-double Math::exp(double x) {
- return ::exp(x);
-}