Browse Source

Add absf() to math.hpp

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
4fe7eed5f0
1 changed files with 6 additions and 2 deletions
  1. +6
    -2
      include/math.hpp

+ 6
- 2
include/math.hpp View File

@@ -51,14 +51,18 @@ inline bool ispow2i(int n) {
// float functions // float functions
//////////////////// ////////////////////


inline float absf(float x) {
return (x < 0.f) ? -x : x;
}

/** Returns 1.0 for positive numbers and -1.0 for negative numbers (including positive/negative zero) */ /** Returns 1.0 for positive numbers and -1.0 for negative numbers (including positive/negative zero) */
inline float sgnf(float x) { inline float sgnf(float x) {
return copysignf(1.0, x);
return copysignf(1.f, x);
} }


inline float eucmodf(float a, float base) { inline float eucmodf(float a, float base) {
float mod = fmodf(a, base); float mod = fmodf(a, base);
return mod < 0.0 ? mod + base : mod;
return (mod < 0.f) ? mod + base : mod;
} }


inline float nearf(float a, float b, float epsilon = 1e-6) { inline float nearf(float a, float b, float epsilon = 1e-6) {


Loading…
Cancel
Save