10static constexpr float JPH_PI = 3.14159265358979323846f;
15 return inV * (JPH_PI / 180.0f);
21 return inV * (180.0f / JPH_PI);
31 while (inV < -JPH_PI);
33 else if (inV > JPH_PI)
45constexpr T
Clamp(T inV, T inMin, T inMax)
47 return min(max(inV, inMin), inMax);
61 return inV * inV * inV;
68 return inV < 0? T(-1) : T(1);
75 return (inV & (inV - 1)) == 0;
83 return T((
uint64(inV) + inAlignment - 1) & ~(inAlignment - 1));
91 return (
uint64(inV) & (inAlignment - 1)) == 0;
97#if defined(JPH_CPU_X86) || defined(JPH_CPU_WASM)
98 #if defined(JPH_USE_TZCNT)
99 return _tzcnt_u32(inValue);
100 #elif defined(JPH_COMPILER_MSVC)
103 unsigned long result;
104 _BitScanForward(&result, inValue);
109 return __builtin_ctz(inValue);
111#elif defined(JPH_CPU_ARM)
112 #if defined(JPH_COMPILER_MSVC)
115 unsigned long result;
116 _BitScanForward(&result, inValue);
119 return __builtin_clz(__builtin_bitreverse32(inValue));
129#if defined(JPH_CPU_X86) || defined(JPH_CPU_WASM)
130 #if defined(JPH_USE_LZCNT)
131 return _lzcnt_u32(inValue);
132 #elif defined(JPH_COMPILER_MSVC)
135 unsigned long result;
136 _BitScanReverse(&result, inValue);
141 return __builtin_clz(inValue);
143#elif defined(JPH_CPU_ARM)
144 #if defined(JPH_COMPILER_MSVC)
145 return _CountLeadingZeros(inValue);
147 return __builtin_clz(inValue);
157#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
158 return __builtin_popcount(inValue);
159#elif defined(JPH_COMPILER_MSVC)
160 #if defined(JPH_USE_SSE4_2)
161 return _mm_popcnt_u32(inValue);
162 #elif defined(JPH_USE_NEON) && (_MSC_VER >= 1930)
163 return _CountOneBits(inValue);
165 inValue = inValue - ((inValue >> 1) & 0x55555555);
166 inValue = (inValue & 0x33333333) + ((inValue >> 2) & 0x33333333);
167 inValue = (inValue + (inValue >> 4)) & 0x0F0F0F0F;
168 return (inValue * 0x01010101) >> 24;
182template <
class To,
class From>
185 static_assert(std::is_trivially_constructible_v<To>);
186 static_assert(
sizeof(From) ==
sizeof(To));
195 convert.mFrom = inValue;
uint32_t uint32
Definition Core.h:312
unsigned int uint
Definition Core.h:309
#define JPH_NAMESPACE_END
Definition Core.h:240
uint64_t uint64
Definition Core.h:313
#define JPH_NAMESPACE_BEGIN
Definition Core.h:234
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
constexpr T Cubed(T inV)
Returns .
Definition Math.h:59
float CenterAngleAroundZero(float inV)
Convert angle in radians to the range .
Definition Math.h:25
constexpr bool IsPowerOf2(T inV)
Check if inV is a power of 2.
Definition Math.h:73
constexpr T Clamp(T inV, T inMin, T inMax)
Clamp a value between two values.
Definition Math.h:45
uint CountBits(uint32 inValue)
Count the number of 1 bits in a value.
Definition Math.h:155
bool IsAligned(T inV, uint64 inAlignment)
Check if inV is inAlignment aligned.
Definition Math.h:88
constexpr float RadiansToDegrees(float inV)
Convert a value from radians to degrees.
Definition Math.h:19
uint CountTrailingZeros(uint32 inValue)
Compute number of trailing zero bits (how many low bits are zero)
Definition Math.h:95
JPH_INLINE To BitCast(const From &inValue)
Definition Math.h:183
uint CountLeadingZeros(uint32 inValue)
Compute the number of leading zero bits (how many high bits are zero)
Definition Math.h:127
uint32 GetNextPowerOf2(uint32 inValue)
Get the next higher power of 2 of a value, or the value itself if the value is already a power of 2.
Definition Math.h:176
constexpr T Square(T inV)
Square a value.
Definition Math.h:52
constexpr T Sign(T inV)
Get the sign of a value.
Definition Math.h:66
T AlignUp(T inV, uint64 inAlignment)
Align inV up to the next inAlignment bytes.
Definition Math.h:80
constexpr float DegreesToRadians(float inV)
Convert a value from degrees to radians.
Definition Math.h:13