10static constexpr float JPH_PI = 3.14159265358979323846f;
13static constexpr float cLargeFloat = 1.0e15f;
18 return inV * (JPH_PI / 180.0f);
24 return inV * (180.0f / JPH_PI);
34 while (inV < -JPH_PI);
36 else if (inV > JPH_PI)
48JPH_INLINE
constexpr T
Clamp(T inV, T inMin, T inMax)
50 return min(max(inV, inMin), inMax);
62JPH_INLINE
constexpr T
Cubed(T inV)
64 return inV * inV * inV;
69JPH_INLINE
constexpr T
Sign(T inV)
71 return inV < 0? T(-1) : T(1);
78 return inV > 0 && (inV & (inV - 1)) == 0;
86 return T((
uint64(inV) + inAlignment - 1) & ~(inAlignment - 1));
94 return (
uint64(inV) & (inAlignment - 1)) == 0;
100#if defined(JPH_CPU_X86) || defined(JPH_CPU_WASM)
101 #if defined(JPH_USE_TZCNT)
102 return _tzcnt_u32(inValue);
103 #elif defined(JPH_COMPILER_MSVC)
106 unsigned long result;
107 _BitScanForward(&result, inValue);
112 return __builtin_ctz(inValue);
114#elif defined(JPH_CPU_ARM)
115 #if defined(JPH_COMPILER_MSVC)
118 unsigned long result;
119 _BitScanForward(&result, inValue);
124 return __builtin_ctz(inValue);
126#elif defined(JPH_CPU_E2K) || defined(JPH_CPU_RISCV) || defined(JPH_CPU_PPC) || defined(JPH_CPU_LOONGARCH)
127 return inValue ? __builtin_ctz(inValue) : 32;
136#if defined(JPH_CPU_X86) || defined(JPH_CPU_WASM)
137 #if defined(JPH_USE_LZCNT)
138 return _lzcnt_u32(inValue);
139 #elif defined(JPH_COMPILER_MSVC)
142 unsigned long result;
143 _BitScanReverse(&result, inValue);
148 return __builtin_clz(inValue);
150#elif defined(JPH_CPU_ARM)
151 #if defined(JPH_COMPILER_MSVC)
152 return _CountLeadingZeros(inValue);
154 return __builtin_clz(inValue);
156#elif defined(JPH_CPU_E2K) || defined(JPH_CPU_RISCV) || defined(JPH_CPU_PPC) || defined(JPH_CPU_LOONGARCH)
157 return inValue ? __builtin_clz(inValue) : 32;
166#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
167 return __builtin_popcount(inValue);
168#elif defined(JPH_COMPILER_MSVC)
169 #if defined(JPH_USE_SSE4_2)
170 return _mm_popcnt_u32(inValue);
171 #elif defined(JPH_USE_NEON) && (_MSC_VER >= 1930)
172 return _CountOneBits(inValue);
174 inValue = inValue - ((inValue >> 1) & 0x55555555);
175 inValue = (inValue & 0x33333333) + ((inValue >> 2) & 0x33333333);
176 inValue = (inValue + (inValue >> 4)) & 0x0F0F0F0F;
177 return (inValue * 0x01010101) >> 24;
191template <
class To,
class From>
194 static_assert(std::is_trivially_constructible_v<To>);
195 static_assert(
sizeof(From) ==
sizeof(To));
204 convert.mFrom = inValue;
std::uint64_t uint64
Definition Core.h:485
unsigned int uint
Definition Core.h:481
#define JPH_NAMESPACE_END
Definition Core.h:414
std::uint32_t uint32
Definition Core.h:484
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
JPH_INLINE constexpr T Clamp(T inV, T inMin, T inMax)
Clamp a value between two values.
Definition Math.h:48
JPH_INLINE constexpr T Sign(T inV)
Get the sign of a value.
Definition Math.h:69
float CenterAngleAroundZero(float inV)
Convert angle in radians to the range .
Definition Math.h:28
constexpr bool IsPowerOf2(T inV)
Check if inV is a power of 2.
Definition Math.h:76
uint CountBits(uint32 inValue)
Count the number of 1 bits in a value.
Definition Math.h:164
JPH_INLINE constexpr T Square(T inV)
Square a value.
Definition Math.h:55
JPH_INLINE constexpr float DegreesToRadians(float inV)
Convert a value from degrees to radians.
Definition Math.h:16
JPH_INLINE constexpr T Cubed(T inV)
Returns .
Definition Math.h:62
JPH_INLINE constexpr float RadiansToDegrees(float inV)
Convert a value from radians to degrees.
Definition Math.h:22
bool IsAligned(T inV, uint64 inAlignment)
Check if inV is inAlignment aligned.
Definition Math.h:91
uint CountTrailingZeros(uint32 inValue)
Compute number of trailing zero bits (how many low bits are zero)
Definition Math.h:98
JPH_INLINE To BitCast(const From &inValue)
Definition Math.h:192
uint CountLeadingZeros(uint32 inValue)
Compute the number of leading zero bits (how many high bits are zero)
Definition Math.h:134
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:185
T AlignUp(T inV, uint64 inAlignment)
Align inV up to the next inAlignment bytes.
Definition Math.h:83