Plasma Engine  2.0
Loading...
Searching...
No Matches
MathDouble_inl.h
1#pragma once
2
3namespace plMath
4{
5 PL_ALWAYS_INLINE bool IsFinite(double value)
6 {
7 // Check the 11 exponent bits.
8 // NAN -> (exponent = all 1, mantissa = non-zero)
9 // INF -> (exponent = all 1, mantissa = zero)
10
11 plInt64DoubleUnion i2f(value);
12 return ((i2f.i & 0x7FF0000000000000ull) != 0x7FF0000000000000ull);
13 }
14
15 PL_ALWAYS_INLINE bool IsNaN(double value)
16 {
17 // Check the 11 exponent bits.
18 // NAN -> (exponent = all 1, mantissa = non-zero)
19 // INF -> (exponent = all 1, mantissa = zero)
20
21 plInt64DoubleUnion i2f(value);
22 return (((i2f.i & 0x7FF0000000000000ull) == 0x7FF0000000000000ull) && ((i2f.i & 0xFFFFFFFFFFFFFull) != 0));
23 }
24
25 PL_ALWAYS_INLINE double Floor(double f)
26 {
27 return floor(f);
28 }
29
30 PL_ALWAYS_INLINE double Ceil(double f)
31 {
32 return ceil(f);
33 }
34
35 PL_ALWAYS_INLINE double Round(double f)
36 {
37 return Floor(f + 0.5f);
38 }
39
40 inline double RoundDown(double f, double fMultiple)
41 {
42 double fDivides = f / fMultiple;
43 double fFactor = Floor(fDivides);
44 return fFactor * fMultiple;
45 }
46
47 inline double RoundUp(double f, double fMultiple)
48 {
49 double fDivides = f / fMultiple;
50 double fFactor = Ceil(fDivides);
51 return fFactor * fMultiple;
52 }
53
54 PL_ALWAYS_INLINE double RoundToMultiple(double f, double fMultiple)
55 {
56 return Round(f / fMultiple) * fMultiple;
57 }
58
59 PL_ALWAYS_INLINE double Exp(double f)
60 {
61 return exp(f);
62 }
63
64 PL_ALWAYS_INLINE double Ln(double f)
65 {
66 return log(f);
67 }
68
69 PL_ALWAYS_INLINE double Log2(double f)
70 {
71 return log10(f) / log10(2.0);
72 }
73
74 PL_ALWAYS_INLINE double Log10(double f)
75 {
76 return log10(f);
77 }
78
79 PL_ALWAYS_INLINE double Log(double fBase, double f)
80 {
81 return log10(f) / log10(fBase);
82 }
83
84 PL_ALWAYS_INLINE double Pow2(double f)
85 {
86 return pow(2.0, f);
87 }
88
89 PL_ALWAYS_INLINE double Pow(double fBase, double fExp)
90 {
91 return pow(fBase, fExp);
92 }
93
94 PL_ALWAYS_INLINE double Root(double f, double fNthRoot)
95 {
96 return pow(f, 1.0 / fNthRoot);
97 }
98
99 PL_ALWAYS_INLINE double Sqrt(double f)
100 {
101 return sqrt(f);
102 }
103
104 PL_ALWAYS_INLINE double Mod(double f, double fDiv)
105 {
106 return fmod(f, fDiv);
107 }
108} // namespace plMath
This namespace provides common math-functionality as functions.
Definition Constants.h:6
double RoundDown(double f, double fMultiple)
Returns a multiple of fMultiple that is smaller than f.
Definition MathDouble_inl.h:40
PL_ALWAYS_INLINE double RoundToMultiple(double f, double fMultiple)
Rounds f to the closest value of multiple.
Definition MathDouble_inl.h:54
PL_ALWAYS_INLINE double Round(double f)
Rounds f to the next integer.
Definition MathDouble_inl.h:35
double RoundUp(double f, double fMultiple)
Returns a multiple of fMultiple that is larger than f.
Definition MathDouble_inl.h:47
PL_ALWAYS_INLINE double Mod(double f, double fDiv)
Returns "value mod div" for doubles. This also works with negative numbers, both for value and for di...
Definition MathDouble_inl.h:104
PL_ALWAYS_INLINE double Sqrt(double f)
Returns the square root of f.
Definition MathDouble_inl.h:99
Simple helper union to store ints and doubles to modify their bit patterns.
Definition Declarations.h:35