Plasma Engine  2.0
Loading...
Searching...
No Matches
MathInt32_inl.h
1#pragma once
2
3namespace plMath
4{
5 constexpr PL_ALWAYS_INLINE plInt32 RoundUp(plInt32 value, plUInt16 uiMultiple)
6 {
7 //
8 return (value >= 0) ? ((value + uiMultiple - 1) / uiMultiple) * uiMultiple : (value / uiMultiple) * uiMultiple;
9 }
10
11 constexpr PL_ALWAYS_INLINE plInt32 RoundDown(plInt32 value, plUInt16 uiMultiple)
12 {
13 //
14 return (value <= 0) ? ((value - uiMultiple + 1) / uiMultiple) * uiMultiple : (value / uiMultiple) * uiMultiple;
15 }
16
17 constexpr PL_ALWAYS_INLINE plUInt32 RoundUp(plUInt32 value, plUInt16 uiMultiple)
18 {
19 //
20 return ((value + uiMultiple - 1) / uiMultiple) * uiMultiple;
21 }
22
23 constexpr PL_ALWAYS_INLINE plUInt32 RoundDown(plUInt32 value, plUInt16 uiMultiple)
24 {
25 //
26 return (value / uiMultiple) * uiMultiple;
27 }
28
29 constexpr PL_ALWAYS_INLINE bool IsOdd(plInt32 i)
30 {
31 //
32 return ((i & 1) != 0);
33 }
34
35 constexpr PL_ALWAYS_INLINE bool IsEven(plInt32 i)
36 {
37 //
38 return ((i & 1) == 0);
39 }
40
41 PL_ALWAYS_INLINE plUInt32 Log2i(plUInt32 uiVal)
42 {
43 return (uiVal != 0) ? FirstBitHigh(uiVal) : -1;
44 }
45
46 constexpr PL_ALWAYS_INLINE int Pow2(int i)
47 {
48 //
49 return (1 << i);
50 }
51
52 inline int Pow(int iBase, int iExp)
53 {
54 int res = 1;
55 while (iExp > 0)
56 {
57 res *= iBase;
58 --iExp;
59 }
60
61 return res;
62 }
63
64} // 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 plUInt32 FirstBitHigh(plUInt32 value)
Returns the index of the most significant bit set.
Definition Math_inl.h:119
double RoundUp(double f, double fMultiple)
Returns a multiple of fMultiple that is larger than f.
Definition MathDouble_inl.h:47
constexpr PL_ALWAYS_INLINE bool IsOdd(plInt32 i)
Returns true, if i is an odd number.
Definition MathInt32_inl.h:29
constexpr PL_ALWAYS_INLINE bool IsEven(plInt32 i)
Returns true, if i is an even number.
Definition MathInt32_inl.h:35
PL_ALWAYS_INLINE plUInt32 Log2i(plUInt32 uiVal)
Returns the integral logarithm to the base 2, that comes closest to the given integer.
Definition MathInt32_inl.h:41