FMath.hpp 2.94 KB
 berenger-bramas committed Apr 26, 2011 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 ``````#ifndef FMATH_HPP #define FMATH_HPP // /!\ Please, you must read the license at the bottom of this page #include #include "FGlobal.hpp" /** * @author Berenger Bramas (berenger.bramas@inria.fr) * @class * Please read the license * * Propose basic math functions or indirections to std math. */ struct FMath{ static const double FPi; //< Pi constant static const double FPiDiv2; //< Pi/2 constant static const double Epsilon; //< Epsilon /** To get absolute value */ template static NumType Abs(const NumType inV){ return (inV < 0 ? -inV : inV); } /** To get max between 2 values */ template static NumType Max(const NumType inV1, const NumType inV2){ return (inV1 > inV2 ? inV1 : inV2); } /** To get min between 2 values */ template static NumType Min(const NumType inV1, const NumType inV2){ return (inV1 < inV2 ? inV1 : inV2); } /** To know if 2 values seems to be equal */ template static bool LookEqual(const NumType inV1, const NumType inV2){ /*const FReal relTol = 0.00001; const FReal absTol = 0.00001; return (Abs(inV1 - inV2) <= Max(absTol, relTol * Max(Abs(inV1), Abs(inV2))));*/ return Abs(inV1 - inV2) <= (Abs(inV1 < Abs(inV2) ? Abs(inV2) : Abs(inV1)) * 0.00001); } /** To get floor of a FReal */ static FReal dfloor(const FReal inValue){ return floor(inValue); } `````` berenger-bramas committed Apr 28, 2011 52 53 54 55 56 `````` /** To get ceil of a FReal */ static FReal Ceil(const FReal inValue){ return ceil(inValue); } `````` berenger-bramas committed Apr 26, 2011 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 `````` /** To get pow */ template static NumType pow(const NumType inValue, long power){ NumType result = 1; while(power-- > 0) result *= inValue; return result; } /** To know if a value is between two others */ template static bool Between(const NumType inValue, const NumType inMin, const NumType inMax){ return ( inMin <= inValue && inValue < inMax ); } /** To get sqrt of a FReal */ static FReal Sqrt(const FReal inValue){ return sqrt(inValue); } /** To get atan2 of a 2 FReal */ static FReal Atan2(const FReal inValue1,const FReal inValue2){ return atan2(inValue1,inValue2); } /** To get sqrt of a FReal */ static FReal Sin(const FReal inValue){ return sin(inValue); } /** To get cos of a FReal */ static FReal Cos(const FReal inValue){ return cos(inValue); } /** To get acos of a FReal */ static FReal ACos(const FReal inValue){ return acos(inValue); } /** To get atan2 of a 2 FReal */ static FReal Fmod(const FReal inValue1,const FReal inValue2){ return fmod(inValue1,inValue2); } }; const double FMath::FPi = M_PI; const double FMath::FPiDiv2 = M_PI_2; const double FMath::Epsilon = 0.00000000000000000001; #endif //FMATH_HPP // [--LICENSE--]``````