UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GenericPlatformMath.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3
4/*=============================================================================================
5 GenericPlatformMath.h: Generic platform Math classes, mostly implemented with ANSI C++
6==============================================================================================*/
7
8#pragma once
9
10#include "CoreTypes.h"
11#include "Concepts/Integral.h"
13#include "HAL/PlatformCrt.h"
14#include "Templates/AndOrNot.h"
15#include "Templates/Decay.h"
18#include "Templates/Requires.h"
21#include <limits>
22#include <type_traits>
23
24#if PLATFORM_HAS_FENV_H
25#include <fenv.h>
26#endif
27
32{
33 // load half (F16) to float
34 //https://gist.github.com/rygorous/2156668
35 [[nodiscard]] static constexpr inline float LoadHalf(const uint16* Ptr)
36 {
37 uint16 FP16 = *Ptr;
38 constexpr uint32 shifted_exp = 0x7c00 << 13; // exponent mask after shift
39 union FP32T
40 {
41 uint32 u;
42 float f;
43 } FP32 = {}, magic = { 113 << 23 };
44
45 FP32.u = (FP16 & 0x7fff) << 13; // exponent/mantissa bits
46 uint32 exp = shifted_exp & FP32.u; // just the exponent
47 FP32.u += uint32(127 - 15) << 23; // exponent adjust
48
49 // handle exponent special cases
50 if (exp == shifted_exp) // Inf/NaN?
51 {
52 FP32.u += uint32(128 - 16) << 23; // extra exp adjust
53 }
54 else if (exp == 0) // Zero/Denormal?
55 {
56 FP32.u += 1 << 23; // extra exp adjust
57 FP32.f -= magic.f; // renormalize
58 }
59
60 FP32.u |= (FP16 & 0x8000) << 16; // sign bit
61 return FP32.f;
62 }
63
64 // store float to half (F16)
65 // converts with RTNE = round to nearest even
66 // values too large for F16 are stored as +-Inf
67 // https://gist.github.com/rygorous/2156668
68 // float_to_half_fast3_rtne
69 static constexpr inline void StoreHalf(uint16* Ptr, float Value)
70 {
71 union FP32T
72 {
73 uint32 u;
74 float f;
75 } FP32 = {};
76 uint16 FP16 = {};
77
78 FP32.f = Value;
79
80 constexpr FP32T f32infty = { uint32(255 << 23) };
81 constexpr FP32T f16max = { uint32(127 + 16) << 23 };
82 constexpr FP32T denorm_magic = { (uint32(127 - 15) + uint32(23 - 10) + 1) << 23 };
83 constexpr uint32 sign_mask = 0x80000000u;
84
86 FP32.u ^= sign;
87
88 // NOTE all the integer compares in this function can be safely
89 // compiled into signed compares since all operands are below
90 // 0x80000000. Important if you want fast straight SSE2 code
91 // (since there's no unsigned PCMPGTD).
92
93 if (FP32.u >= f16max.u) // result is Inf or NaN (all exponent bits set)
94 {
95 FP16 = (FP32.u > f32infty.u) ? 0x7e00 : 0x7c00; // NaN->qNaN and Inf->Inf
96 }
97 else // (De)normalized number or zero
98 {
99 if (FP32.u < uint32(113 << 23)) // resulting FP16 is subnormal or zero
100 {
101 // use a magic value to align our 10 mantissa bits at the bottom of
102 // the float. as long as FP addition is round-to-nearest-even this
103 // just works.
104 FP32.f += denorm_magic.f;
105
106 // and one integer subtract of the bias later, we have our final float!
107 FP16 = uint16(FP32.u - denorm_magic.u);
108 }
109 else
110 {
111 uint32 mant_odd = (FP32.u >> 13) & 1; // resulting mantissa is odd
112
113 // update exponent, rounding bias part 1
114 FP32.u += (uint32(15 - 127) << 23) + 0xfff;
115 // rounding bias part 2
116 FP32.u += mant_odd;
117 // take the bits!
118 FP16 = uint16(FP32.u >> 13);
119 }
120 }
121
122 FP16 |= sign >> 16;
123 *Ptr = FP16;
124 }
125
126 static constexpr inline void VectorLoadHalf(float* RESTRICT Dst, const uint16* RESTRICT Src)
127 {
128 Dst[0] = LoadHalf(&Src[0]);
129 Dst[1] = LoadHalf(&Src[1]);
130 Dst[2] = LoadHalf(&Src[2]);
131 Dst[3] = LoadHalf(&Src[3]);
132 }
133
134 static constexpr inline void VectorStoreHalf(uint16* RESTRICT Dst, const float* RESTRICT Src)
135 {
136 StoreHalf(&Dst[0], Src[0]);
137 StoreHalf(&Dst[1], Src[1]);
138 StoreHalf(&Dst[2], Src[2]);
139 StoreHalf(&Dst[3], Src[3]);
140 }
141
142 static constexpr inline void WideVectorLoadHalf(float* RESTRICT Dst, const uint16* RESTRICT Src)
143 {
144 VectorLoadHalf(Dst, Src);
145 VectorLoadHalf(Dst + 4, Src + 4);
146 }
147
148 static constexpr inline void WideVectorStoreHalf(uint16* RESTRICT Dst, const float* RESTRICT Src)
149 {
150 VectorStoreHalf(Dst, Src);
151 VectorStoreHalf(Dst + 4, Src + 4);
152 }
153
159 [[nodiscard]] static inline uint32 AsUInt(float F)
160 {
161 uint32 U{};
162 static_assert(sizeof(F) == sizeof(U), "The float and uint sizes must be equal");
163 ::memcpy(&U, &F, sizeof(F));
164 return U;
165 }
166
172 [[nodiscard]] static inline uint64 AsUInt(double D)
173 {
174 uint64 U{};
175 static_assert(sizeof(D) == sizeof(U), "The float and uint sizes must be equal");
176 ::memcpy(&U, &D, sizeof(D));
177 return U;
178 }
179
185 [[nodiscard]] static inline float AsFloat(uint32 U)
186 {
187 float F{};
188 static_assert(sizeof(F) == sizeof(U), "The float and uint32 sizes must be equal");
189 ::memcpy(&F, &U, sizeof(U));
190 return F;
191 }
192
198 [[nodiscard]] static inline double AsFloat(uint64 U)
199 {
200 double F{};
201 static_assert(sizeof(F) == sizeof(U), "The double and uint64 sizes must be equal");
202 ::memcpy(&F, &U, sizeof(F));
203 return F;
204 }
205
206
213 {
214 return (int32)F;
215 }
216 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT int32 TruncToInt32(double F)
217 {
218 return (int32)F;
219 }
220 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT int64 TruncToInt64(double F)
221 {
222 return (int64)F;
223 }
224
225 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT int32 TruncToInt(float F) { return TruncToInt32(F); }
226 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT int64 TruncToInt(double F) { return TruncToInt64(F); }
227
234 {
235 return truncf(F);
236 }
237
244 {
245 return trunc(F);
246 }
247
248 [[nodiscard]] static UE_FORCEINLINE_HINT double TruncToFloat(double F)
249 {
250 return TruncToDouble(F);
251 }
252
258 [[nodiscard]] static inline int32 FloorToInt32(float F)
259 {
260 int32 I = TruncToInt32(F);
261 I -= ((float)I > F);
262 return I;
263 }
264 [[nodiscard]] static inline int32 FloorToInt32(double F)
265 {
266 int32 I = TruncToInt32(F);
267 I -= ((double)I > F);
268 return I;
269 }
270 [[nodiscard]] static inline int64 FloorToInt64(double F)
271 {
272 int64 I = TruncToInt64(F);
273 I -= ((double)I > F);
274 return I;
275 }
276
279
280
287 {
288 return floorf(F);
289 }
290
297 {
298 return floor(F);
299 }
300
301 [[nodiscard]] static UE_FORCEINLINE_HINT double FloorToFloat(double F)
302 {
303 return FloorToDouble(F);
304 }
305
312 {
313 return FloorToInt32(F + 0.5f);
314 }
316 {
317 return FloorToInt32(F + 0.5);
318 }
320 {
321 return FloorToInt64(F + 0.5);
322 }
323
326
333 {
334 return FloorToFloat(F + 0.5f);
335 }
336
343 {
344 return FloorToDouble(F + 0.5);
345 }
346
347 [[nodiscard]] static UE_FORCEINLINE_HINT double RoundToFloat(double F)
348 {
349 return RoundToDouble(F);
350 }
351
357 [[nodiscard]] static inline int32 CeilToInt32(float F)
358 {
359 int32 I = TruncToInt32(F);
360 I += ((float)I < F);
361 return I;
362 }
363 [[nodiscard]] static inline int32 CeilToInt32(double F)
364 {
365 int32 I = TruncToInt32(F);
366 I += ((double)I < F);
367 return I;
368 }
369 [[nodiscard]] static inline int64 CeilToInt64(double F)
370 {
371 int64 I = TruncToInt64(F);
372 I += ((double)I < F);
373 return I;
374 }
375
378
385 {
386 return ceilf(F);
387 }
388
394 [[nodiscard]] static UE_FORCEINLINE_HINT double CeilToDouble(double F)
395 {
396 return ceil(F);
397 }
398
399 [[nodiscard]] static UE_FORCEINLINE_HINT double CeilToFloat(double F)
400 {
401 return CeilToDouble(F);
402 }
403
411 {
412#if PLATFORM_HAS_FENV_H == 0
413 ensureAlwaysMsgf(FLT_ROUNDS == 1, TEXT("Platform does not support FE_TONEAREST for double to int64."));
414 int64 result = llrint(F);
415#else
418 {
420 }
421 int64 result = llrint(F);
423 {
425 }
426#endif
427 return result;
428 }
429
436 {
437 return Value - TruncToFloat(Value);
438 }
439
441 {
442 return Value - TruncToDouble(Value);
443 }
444
450 [[nodiscard]] static UE_FORCEINLINE_HINT float Frac(float Value)
451 {
452 return Value - FloorToFloat(Value);
453 }
454
455
456 [[nodiscard]] static UE_FORCEINLINE_HINT double Frac(double Value)
457 {
458 return Value - FloorToDouble(Value);
459 }
460
467 [[nodiscard]] static UE_FORCEINLINE_HINT float Modf(const float InValue, float* OutIntPart)
468 {
469 return modff(InValue, OutIntPart);
470 }
471
478 [[nodiscard]] static UE_FORCEINLINE_HINT double Modf(const double InValue, double* OutIntPart)
479 {
480 return modf(InValue, OutIntPart);
481 }
482
483 // Returns e^Value
484#if PLATFORM_WINDOWS && PLATFORM_CPU_ARM_FAMILY
485 [[nodiscard]] static UE_FORCEINLINE_HINT float Exp( volatile float Value ) { return expf(Value); } // #jira UE-261901 : workaround optimization bug for expf()
486#else
487 [[nodiscard]] static UE_FORCEINLINE_HINT float Exp( float Value ) { return expf(Value); }
488#endif
489 [[nodiscard]] static UE_FORCEINLINE_HINT double Exp(double Value) { return exp(Value); }
490
491 // Returns 2^Value
492 [[nodiscard]] static UE_FORCEINLINE_HINT float Exp2( float Value ) { return powf(2.f, Value); /*exp2f(Value);*/ }
493 [[nodiscard]] static UE_FORCEINLINE_HINT double Exp2(double Value) { return pow(2.0, Value); /*exp2(Value);*/ }
494
495 [[nodiscard]] static UE_FORCEINLINE_HINT float Loge( float Value ) { return logf(Value); }
496 [[nodiscard]] static UE_FORCEINLINE_HINT double Loge(double Value) { return log(Value); }
497
498 [[nodiscard]] static UE_FORCEINLINE_HINT float LogX( float Base, float Value ) { return Loge(Value) / Loge(Base); }
499 [[nodiscard]] static UE_FORCEINLINE_HINT double LogX(double Base, double Value) { return Loge(Value) / Loge(Base); }
501
502 // 1.0 / Loge(2) = 1.4426950f
503 [[nodiscard]] static UE_FORCEINLINE_HINT float Log2( float Value ) { return Loge(Value) * 1.4426950f; }
504 // 1.0 / Loge(2) = 1.442695040888963387
505 [[nodiscard]] static UE_FORCEINLINE_HINT double Log2(double Value) { return Loge(Value) * 1.442695040888963387; }
506
517 [[nodiscard]] static CORE_API FORCENOINLINE float Fmod(float X, float Y);
518 [[nodiscard]] static CORE_API FORCENOINLINE double Fmod(double X, double Y);
520
521 [[nodiscard]] static UE_FORCEINLINE_HINT float Sin( float Value ) { return sinf(Value); }
522 [[nodiscard]] static UE_FORCEINLINE_HINT double Sin( double Value ) { return sin(Value); }
523
524 [[nodiscard]] static UE_FORCEINLINE_HINT float Asin( float Value ) { return asinf( (Value<-1.f) ? -1.f : ((Value<1.f) ? Value : 1.f) ); }
525 [[nodiscard]] static UE_FORCEINLINE_HINT double Asin( double Value ) { return asin( (Value<-1.0) ? -1.0 : ((Value<1.0) ? Value : 1.0) ); }
526
527 [[nodiscard]] static UE_FORCEINLINE_HINT float Sinh(float Value) { return sinhf(Value); }
528 [[nodiscard]] static UE_FORCEINLINE_HINT double Sinh(double Value) { return sinh(Value); }
529
530 [[nodiscard]] static UE_FORCEINLINE_HINT float Cos( float Value ) { return cosf(Value); }
531 [[nodiscard]] static UE_FORCEINLINE_HINT double Cos( double Value ) { return cos(Value); }
532
533 [[nodiscard]] static UE_FORCEINLINE_HINT float Acos( float Value ) { return acosf( (Value<-1.f) ? -1.f : ((Value<1.f) ? Value : 1.f) ); }
534 [[nodiscard]] static UE_FORCEINLINE_HINT double Acos( double Value ) { return acos( (Value<-1.0) ? -1.0 : ((Value<1.0) ? Value : 1.0) ); }
535
536 [[nodiscard]] static UE_FORCEINLINE_HINT float Cosh(float Value) { return coshf(Value); }
537 [[nodiscard]] static UE_FORCEINLINE_HINT double Cosh(double Value) { return cosh(Value); }
538
539 [[nodiscard]] static UE_FORCEINLINE_HINT float Tan( float Value ) { return tanf(Value); }
540 [[nodiscard]] static UE_FORCEINLINE_HINT double Tan( double Value ) { return tan(Value); }
541
542 [[nodiscard]] static UE_FORCEINLINE_HINT float Atan( float Value ) { return atanf(Value); }
543 [[nodiscard]] static UE_FORCEINLINE_HINT double Atan( double Value ) { return atan(Value); }
544
545 [[nodiscard]] static UE_FORCEINLINE_HINT float Tanh(float Value) { return tanhf(Value); }
546 [[nodiscard]] static UE_FORCEINLINE_HINT double Tanh(double Value) { return tanh(Value); }
547
548 [[nodiscard]] static CORE_API float Atan2( float Y, float X );
549 [[nodiscard]] static CORE_API double Atan2( double Y, double X );
551
552 [[nodiscard]] static UE_FORCEINLINE_HINT float Sqrt( float Value ) { return sqrtf(Value); }
553 [[nodiscard]] static UE_FORCEINLINE_HINT double Sqrt( double Value ) { return sqrt(Value); }
554
555 [[nodiscard]] static UE_FORCEINLINE_HINT float Pow( float A, float B ) { return powf(A,B); }
556 [[nodiscard]] static UE_FORCEINLINE_HINT double Pow( double A, double B ) { return pow(A,B); }
558
560 [[nodiscard]] static UE_FORCEINLINE_HINT float InvSqrt( float F ) { return 1.0f / sqrtf( F ); }
561 [[nodiscard]] static UE_FORCEINLINE_HINT double InvSqrt( double F ) { return 1.0 / sqrt( F ); }
562
564 [[nodiscard]] static UE_FORCEINLINE_HINT float InvSqrtEst( float F ) { return InvSqrt( F ); }
565 [[nodiscard]] static UE_FORCEINLINE_HINT double InvSqrtEst( double F ) { return InvSqrt( F ); }
566
568 [[nodiscard]] static UE_FORCEINLINE_HINT float CopySign(float X, float Y) { return copysignf(X, Y); }
569 [[nodiscard]] static UE_FORCEINLINE_HINT double CopySign(double X, double Y) { return copysign(X, Y); }
571
573 [[nodiscard]] static UE_FORCEINLINE_HINT bool IsNaN( float A )
574 {
575 return (BitCast<uint32>(A) & 0x7FFFFFFFU) > 0x7F800000U;
576 }
577 [[nodiscard]] static UE_FORCEINLINE_HINT bool IsNaN(double A)
578 {
579 return (BitCast<uint64>(A) & 0x7FFFFFFFFFFFFFFFULL) > 0x7FF0000000000000ULL;
580 }
581
583 [[nodiscard]] static UE_FORCEINLINE_HINT bool IsFinite( float A )
584 {
585 return (BitCast<uint32>(A) & 0x7F800000U) != 0x7F800000U;
586 }
587 [[nodiscard]] static UE_FORCEINLINE_HINT bool IsFinite(double A)
588 {
589 return (BitCast<uint64>(A) & 0x7FF0000000000000ULL) != 0x7FF0000000000000ULL;
590 }
591
593 {
594 return BitCast<uint32>(A) >= (uint32)0x80000000; // Detects sign bit.
595 }
596
598 {
599 return BitCast<uint64>(A) >= (uint64)0x8000000000000000; // Detects sign bit.
600 }
601
602 UE_DEPRECATED(5.1, "IsNegativeFloat has been deprecated in favor of IsNegativeOrNegativeZero or simply A < 0.")
604 {
606 }
607
608 UE_DEPRECATED(5.1, "IsNegativeDouble has been deprecated in favor of IsNegativeOrNegativeZero or simply A < 0.")
610 {
612 }
613
614 UE_DEPRECATED(5.1, "IsNegative has been deprecated in favor of IsNegativeOrNegativeZero or simply A < 0.")
616 {
618 }
619
620 UE_DEPRECATED(5.1, "IsNegative has been deprecated in favor of IsNegativeOrNegativeZero or simply A < 0.")
622 {
624 }
625
627 [[nodiscard]] static UE_FORCEINLINE_HINT int32 Rand() { return rand(); }
628
630 [[nodiscard]] static UE_FORCEINLINE_HINT int32 Rand32() { return ((rand() & 0x7fff) << 16) | ((rand() & 0x7fff) << 1) | (rand() & 0x1); }
631
634
636 [[nodiscard]] static inline float FRand()
637 {
638 // FP32 mantissa can only represent 24 bits before losing precision
639 constexpr int32 RandMax = 0x00ffffff < RAND_MAX ? 0x00ffffff : RAND_MAX;
640 return (Rand() & RandMax) / (float)RandMax;
641 }
642
644 static CORE_API void SRandInit( int32 Seed );
645
647 [[nodiscard]] static CORE_API int32 GetRandSeed();
648
650 [[nodiscard]] static CORE_API float SRand();
651
659 [[nodiscard]] static constexpr inline uint32 FloorLog2(uint32 Value)
660 {
661 uint32 pos = 0;
662 if (Value >= 1<<16) { Value >>= 16; pos += 16; }
663 if (Value >= 1<< 8) { Value >>= 8; pos += 8; }
664 if (Value >= 1<< 4) { Value >>= 4; pos += 4; }
665 if (Value >= 1<< 2) { Value >>= 2; pos += 2; }
666 if (Value >= 1<< 1) { pos += 1; }
667 return pos;
668 }
669
672 {
673 return FloorLog2(Value);
674 }
675
683 [[nodiscard]] static constexpr inline uint64 FloorLog2_64(uint64 Value)
684 {
685 uint64 pos = 0;
686 if (Value >= 1ull<<32) { Value >>= 32; pos += 32; }
687 if (Value >= 1ull<<16) { Value >>= 16; pos += 16; }
688 if (Value >= 1ull<< 8) { Value >>= 8; pos += 8; }
689 if (Value >= 1ull<< 4) { Value >>= 4; pos += 4; }
690 if (Value >= 1ull<< 2) { Value >>= 2; pos += 2; }
691 if (Value >= 1ull<< 1) { pos += 1; }
692 return pos;
693 }
694
700
708 [[nodiscard]] static constexpr inline uint8 CountLeadingZeros8(uint8 Value)
709 {
710 if (Value == 0) return 8;
711 return uint8(7 - FloorLog2(uint32(Value)));
712 }
713
721 [[nodiscard]] static constexpr inline uint32 CountLeadingZeros(uint32 Value)
722 {
723 if (Value == 0) return 32;
724 return 31 - FloorLog2(Value);
725 }
726
734 [[nodiscard]] static constexpr inline uint64 CountLeadingZeros64(uint64 Value)
735 {
736 if (Value == 0) return 64;
737 return 63 - FloorLog2_64(Value);
738 }
739
747 [[nodiscard]] static constexpr inline uint32 CountTrailingZeros(uint32 Value)
748 {
749 if (Value == 0)
750 {
751 return 32;
752 }
753 uint32 Result = 0;
754 while ((Value & 1) == 0)
755 {
756 Value >>= 1;
757 ++Result;
758 }
759 return Result;
760 }
761
762 UE_DEPRECATED(5.7, "Please use CountTrailingZeros instead")
767
775 [[nodiscard]] static constexpr inline uint64 CountTrailingZeros64(uint64 Value)
776 {
777 if (Value == 0)
778 {
779 return 64;
780 }
781 uint64 Result = 0;
782 while ((Value & 1) == 0)
783 {
784 Value >>= 1;
785 ++Result;
786 }
787 return Result;
788 }
789
790 UE_DEPRECATED(5.7, "Please use CountTrailingZeros64 instead")
795
800 [[nodiscard]] static constexpr inline uint32 CeilLogTwo( uint32 Arg )
801 {
802 // if Arg is 0, change it to 1 so that we return 0
803 Arg = Arg ? Arg : 1;
804 return 32 - CountLeadingZeros(Arg - 1);
805 }
806
807 [[nodiscard]] static constexpr inline uint64 CeilLogTwo64( uint64 Arg )
808 {
809 // if Arg is 0, change it to 1 so that we return 0
810 Arg = Arg ? Arg : 1;
811 return 64 - CountLeadingZeros64(Arg - 1);
812 }
813
818 [[nodiscard]] static constexpr inline uint8 ConstExprCeilLogTwo(SIZE_T Arg)
819 {
820 if (Arg <= 1)
821 {
822 return 0;
823 }
824 // Integer overflow if we tried to add 1 to maximum value, so handle that case separately
825 if (Arg + 1 < Arg)
826 {
827 return sizeof(Arg) * 8;
828 }
829 return 1 + ConstExprCeilLogTwo((Arg + 1) / 2);
830 }
831
834 {
835 return 1u << CeilLogTwo(Arg);
836 }
837
839 {
840 return uint64(1) << CeilLogTwo64(V);
841 }
842
844 [[nodiscard]] static constexpr inline uint32 MortonCode2( uint32 x )
845 {
846 x &= 0x0000ffff;
847 x = (x ^ (x << 8)) & 0x00ff00ff;
848 x = (x ^ (x << 4)) & 0x0f0f0f0f;
849 x = (x ^ (x << 2)) & 0x33333333;
850 x = (x ^ (x << 1)) & 0x55555555;
851 return x;
852 }
853
854 [[nodiscard]] static constexpr inline uint64 MortonCode2_64( uint64 x )
855 {
856 x &= 0x00000000ffffffff;
857 x = (x ^ (x << 16)) & 0x0000ffff0000ffff;
858 x = (x ^ (x << 8)) & 0x00ff00ff00ff00ff;
859 x = (x ^ (x << 4)) & 0x0f0f0f0f0f0f0f0f;
860 x = (x ^ (x << 2)) & 0x3333333333333333;
861 x = (x ^ (x << 1)) & 0x5555555555555555;
862 return x;
863 }
864
866 [[nodiscard]] static constexpr inline uint32 ReverseMortonCode2( uint32 x )
867 {
868 x &= 0x55555555;
869 x = (x ^ (x >> 1)) & 0x33333333;
870 x = (x ^ (x >> 2)) & 0x0f0f0f0f;
871 x = (x ^ (x >> 4)) & 0x00ff00ff;
872 x = (x ^ (x >> 8)) & 0x0000ffff;
873 return x;
874 }
875
876 [[nodiscard]] static constexpr inline uint64 ReverseMortonCode2_64( uint64 x )
877 {
878 x &= 0x5555555555555555;
879 x = (x ^ (x >> 1)) & 0x3333333333333333;
880 x = (x ^ (x >> 2)) & 0x0f0f0f0f0f0f0f0f;
881 x = (x ^ (x >> 4)) & 0x00ff00ff00ff00ff;
882 x = (x ^ (x >> 8)) & 0x0000ffff0000ffff;
883 x = (x ^ (x >> 16)) & 0x00000000ffffffff;
884 return x;
885 }
886
888 [[nodiscard]] static constexpr inline uint32 MortonCode3( uint32 x )
889 {
890 x &= 0x000003ff;
891 x = (x ^ (x << 16)) & 0xff0000ff;
892 x = (x ^ (x << 8)) & 0x0300f00f;
893 x = (x ^ (x << 4)) & 0x030c30c3;
894 x = (x ^ (x << 2)) & 0x09249249;
895 return x;
896 }
897
899 [[nodiscard]] static constexpr inline uint32 ReverseMortonCode3( uint32 x )
900 {
901 x &= 0x09249249;
902 x = (x ^ (x >> 2)) & 0x030c30c3;
903 x = (x ^ (x >> 4)) & 0x0300f00f;
904 x = (x ^ (x >> 8)) & 0xff0000ff;
905 x = (x ^ (x >> 16)) & 0x000003ff;
906 return x;
907 }
908
923 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT float FloatSelect( float Comparand, float ValueGEZero, float ValueLTZero )
924 {
925 return Comparand >= 0.f ? ValueGEZero : ValueLTZero;
926 }
927
942 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT double FloatSelect( double Comparand, double ValueGEZero, double ValueLTZero )
943 {
944 return Comparand >= 0.0 ? ValueGEZero : ValueLTZero;
945 }
946
948 template< class T >
949 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT T Abs( const T A )
950 {
951 return (A < (T)0) ? (T)-A : A;
952 }
953
955 template< class T >
956 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT T Sign( const T A )
957 {
958 return (A > (T)0) ? (T)1 : ((A < (T)0) ? (T)-1 : (T)0);
959 }
960
962 template <typename T>
963 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT T Max(T A, T B)
964 {
965 // Even though this should be covered by the variadic, we still need this overload because of the many instances of
966 // FMath::Max<T>(a, b) with an explicit template parameter, which needs to continue to be supported.
967
968 return (B < A) ? A : B;
969 }
970 template <
971 typename T, typename... OtherTypes
972 UE_REQUIRES((std::is_same_v<T, OtherTypes> && ...))
973 >
974 [[nodiscard]] static constexpr inline T Max(T A, OtherTypes... Others)
975 {
976 if constexpr (sizeof...(OtherTypes) > 0)
977 {
979 }
980 return A;
981 }
982
984 template <typename T>
985 [[nodiscard]] static constexpr UE_FORCEINLINE_HINT T Min(T A, T B)
986 {
987 // Even though this should be covered by the variadic, we still need this overload because of the many instances of
988 // FMath::Min<T>(a, b) with an explicit template parameter, which needs to continue to be supported.
989
990 return (A < B) ? A : B;
991 }
992 template <
993 typename T, typename... OtherTypes
994 UE_REQUIRES((std::is_same_v<T, OtherTypes> && ...))
995 >
996 [[nodiscard]] static constexpr inline T Min(T A, OtherTypes... Others)
997 {
998 if constexpr (sizeof...(OtherTypes) > 0)
999 {
1001 }
1002 return A;
1003 }
1004
1005 // Allow mixing of float types to promote to highest precision type
1008
1009 // Allow mixing of signed integral types.
1012
1018 template< class T >
1019 [[nodiscard]] static inline T Min(const TArray<T>& Values)
1020 {
1021 if (Values.Num() == 0)
1022 {
1023 return T();
1024 }
1025
1026 T CurMin = Values[0];
1027 for (int32 v = 1; v < Values.Num(); ++v)
1028 {
1029 const T Value = Values[v];
1030 if (Value < CurMin)
1031 {
1032 CurMin = Value;
1033 }
1034 }
1035 return CurMin;
1036 }
1037
1044 template< class T >
1045 static inline T Min(const TArray<T>& Values, int32* MinIndex)
1046 {
1047 if (Values.Num() == 0)
1048 {
1049 if (MinIndex)
1050 {
1051 *MinIndex = INDEX_NONE;
1052 }
1053 return T();
1054 }
1055
1056 T CurMin = Values[0];
1057 int32 CurMinIndex = 0;
1058 for (int32 v = 1; v < Values.Num(); ++v)
1059 {
1060 const T Value = Values[v];
1061 if (Value < CurMin)
1062 {
1063 CurMin = Value;
1064 CurMinIndex = v;
1065 }
1066 }
1067
1068 if (MinIndex)
1069 {
1070 *MinIndex = CurMinIndex;
1071 }
1072 return CurMin;
1073 }
1074
1080 template< class T >
1081 [[nodiscard]] static inline T Max(const TArray<T>& Values)
1082 {
1083 if (Values.Num() == 0)
1084 {
1085 return T();
1086 }
1087
1088 T CurMax = Values[0];
1089 for (int32 v = 1; v < Values.Num(); ++v)
1090 {
1091 const T Value = Values[v];
1092 if (CurMax < Value)
1093 {
1094 CurMax = Value;
1095 }
1096 }
1097
1098 return CurMax;
1099 }
1100
1107 template< class T >
1108 static inline T Max(const TArray<T>& Values, int32* MaxIndex)
1109 {
1110 if (Values.Num() == 0)
1111 {
1112 if (MaxIndex)
1113 {
1114 *MaxIndex = INDEX_NONE;
1115 }
1116 return T();
1117 }
1118
1119 T CurMax = Values[0];
1120 int32 CurMaxIndex = 0;
1121 for (int32 v = 1; v < Values.Num(); ++v)
1122 {
1123 const T Value = Values[v];
1124 if (CurMax < Value)
1125 {
1126 CurMax = Value;
1127 CurMaxIndex = v;
1128 }
1129 }
1130
1131 if (MaxIndex)
1132 {
1133 *MaxIndex = CurMaxIndex;
1134 }
1135 return CurMax;
1136 }
1137
1141 template< class T >
1142 static constexpr inline void GetMinMax(const T& A, const T& B, T& OutMin, T& OutMax)
1143 {
1144 if (A < B)
1145 {
1146 OutMin = A;
1147 OutMax = B;
1148 }
1149 else
1150 {
1151 OutMin = B;
1152 OutMax = A;
1153 }
1154 }
1155
1159 template< class T >
1160 static constexpr inline void GetMinMax(T& Min, T& Max)
1161 {
1162 if (Max < Min)
1163 {
1164 Swap(Min, Max);
1165 }
1166 }
1167
1168 [[nodiscard]] static constexpr inline int32 CountBits(uint64 Bits)
1169 {
1170 // https://en.wikipedia.org/wiki/Hamming_weight
1171 Bits -= (Bits >> 1) & 0x5555555555555555ull;
1172 Bits = (Bits & 0x3333333333333333ull) + ((Bits >> 2) & 0x3333333333333333ull);
1173 Bits = (Bits + (Bits >> 4)) & 0x0f0f0f0f0f0f0f0full;
1174 return (Bits * 0x0101010101010101) >> 56;
1175 }
1176
1177#if WITH_DEV_AUTOMATION_TESTS
1179 static void AutoTest();
1180#endif
1181
1187 template <UE::CIntegral IntType>
1188 [[nodiscard]] static inline bool AddAndCheckForOverflow(IntType A, IntType B, IntType& OutResult)
1189 {
1190 // This follows Hacker's Delight, Chapter 2-12
1191 // Signed->unsigned conversion and unsigned addition have defined behavior always
1192 typedef typename std::make_unsigned_t<IntType> UnsignedType;
1193 const UnsignedType UnsignedA = static_cast<UnsignedType>(A);
1194 const UnsignedType UnsignedB = static_cast<UnsignedType>(B);
1195 const UnsignedType UnsignedSum = UnsignedA + UnsignedB;
1196
1197 if constexpr (std::is_signed_v<IntType>)
1198 {
1199 // Check for signed overflow.
1200 // The underlying logic here is pretty simple: if A and B had opposite signs, their sum can't
1201 // overflow. If they had the same sign and the sum has the opposite value in the sign bit, we
1202 // had an overflow. (See Hacker's Delight Chapter 2-12 for more details.)
1203 constexpr UnsignedType UnsignedMSB = static_cast<UnsignedType>(std::numeric_limits<IntType>::min());
1205 {
1206 return false;
1207 }
1208 else
1209 {
1210 OutResult = A + B;
1211 return true;
1212 }
1213 }
1214 else
1215 {
1216 // Iff there was overflow, the modular sum must be less than both the operands.
1217 if (UnsignedSum >= UnsignedA)
1218 {
1220 return true;
1221 }
1222 else
1223 {
1224 return false;
1225 }
1226 }
1227 }
1228
1234 template <UE::CIntegral IntType>
1235 [[nodiscard]] static inline bool SubtractAndCheckForOverflow(IntType A, IntType B, IntType& OutResult)
1236 {
1237 // This follows Hacker's Delight, Chapter 2-12
1238 // Signed->unsigned conversion and unsigned addition have defined behavior always
1239 typedef typename std::make_unsigned_t<IntType> UnsignedType;
1240 const UnsignedType UnsignedA = static_cast<UnsignedType>(A);
1241 const UnsignedType UnsignedB = static_cast<UnsignedType>(B);
1242 const UnsignedType UnsignedDiff = UnsignedA - UnsignedB;
1243
1244 if constexpr (std::is_signed_v<IntType>)
1245 {
1246 // Check for signed overflow.
1247 // If A and B have the same sign, the difference can't overflow. Therefore, we test for cases
1248 // where the sign bit differs meaning ((UnsignedA ^ UnsignedB) & UnsignedMSB) != 0, and
1249 // simultaneously the sign of the difference differs from the sign of the minuend (which should
1250 // keep its sign when we're subtracting a value of the opposite sign), meaning
1251 // ((UnsignedDiff ^ UnsignedA) & UnsignedMSB) != 0. Combining the two yields:
1252 constexpr UnsignedType UnsignedMSB = static_cast<UnsignedType>(std::numeric_limits<IntType>::min());
1254 {
1255 return false;
1256 }
1257 else
1258 {
1259 OutResult = A - B;
1260 return true;
1261 }
1262 }
1263 else
1264 {
1266 return A >= B;
1267 }
1268 }
1269
1275 template <UE::CIntegral IntType>
1276 [[nodiscard]] static inline bool MultiplyAndCheckForOverflow(IntType A, IntType B, IntType& OutResult)
1277 {
1278 // Handle the case where the second factor is 0 specially (why will become clear in a minute).
1279 if (B == 0)
1280 {
1281 // Anything times 0 is 0.
1282 OutResult = 0;
1283 return true;
1284 }
1285
1286 if constexpr (std::is_signed_v<IntType>)
1287 {
1288 // The overflow check is annoying and expensive, but the basic idea is fairly simple:
1289 // reduce to an unsigned check of the absolute values. (Again the basic algorithm is
1290 // in Hacker's Delight, Chapter 2-12).
1291 //
1292 // We need the absolute value of the product to be <=MaxValue when the result is positive
1293 // (signs of factors same) and <= -MinValue = MaxValue + 1 if the result is negative
1294 // (signs of factors opposite).
1295 typedef typename std::make_unsigned_t<IntType> UnsignedType;
1296 UnsignedType UnsignedA = static_cast<UnsignedType>(A);
1297 UnsignedType UnsignedB = static_cast<UnsignedType>(B);
1298 bool bSignsDiffer = false;
1299
1300 // Determine the unsigned absolute values of A and B carefully (note we can't negate signed
1301 // A or B, because negating MinValue is UB). We can however subtract their
1302 // unsigned values from 0 if the original value was less than zero. While doing this, also
1303 // keep track of the sign parity.
1304 if (A < 0)
1305 {
1306 UnsignedA = UnsignedType(0) - UnsignedA;
1308 }
1309
1310 if (B < 0)
1311 {
1312 UnsignedB = UnsignedType(0) - UnsignedB;
1314 }
1315
1316 // Determine the unsigned product bound we need based on whether the signs were same or different.
1317 const UnsignedType ProductBound = UnsignedType(std::numeric_limits<IntType>::max()) + (bSignsDiffer ? 1 : 0);
1318
1319 // We're now in the unsigned case, 0 <= UnsignedA, 0 < UnsignedB (we established b != 0), and for
1320 // there not to be overflows we need
1321 // a * b <= ProductBound
1322 // <=> a <= ProductBound/b
1323 // <=> a <= floor(ProductBound/b) since a is integer
1325 {
1326 OutResult = A * B;
1327 return true;
1328 }
1329 else
1330 {
1331 return false;
1332 }
1333 }
1334 else
1335 {
1336 OutResult = A * B;
1337 return OutResult / B == A;
1338 }
1339 }
1340
1341private:
1342
1344 static CORE_API void FmodReportError(float X, float Y);
1345 static CORE_API void FmodReportError(double X, double Y);
1346};
1347
1349template<>
1351{
1352 return fabsf( A );
1353}
1354template<>
1356{
1357 return fabs(A);
1358}
#define FORCENOINLINE
Definition AndroidPlatform.h:142
#define ensureAlwaysMsgf(InExpression, InFormat,...)
Definition AssertionMacros.h:467
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
#define RESTRICT
Definition Platform.h:706
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define X(Name, Desc)
Definition FormatStringSan.h:47
#define UE_REQUIRES(...)
Definition Requires.h:86
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
memcpy(InputBufferBase, BinkBlocksData, BinkBlocksSize)
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
float v
Definition radaudio_mdct.cpp:62
Definition GenericPlatformMath.h:32
static constexpr UE_FORCEINLINE_HINT int32 TruncToInt(float F)
Definition GenericPlatformMath.h:225
static constexpr UE_FORCEINLINE_HINT uint64 RoundUpToPowerOfTwo64(uint64 V)
Definition GenericPlatformMath.h:838
static UE_FORCEINLINE_HINT bool IsNegative(double A)
Definition GenericPlatformMath.h:621
static constexpr T Min(T A, OtherTypes... Others)
Definition GenericPlatformMath.h:996
static UE_FORCEINLINE_HINT float Cosh(float Value)
Definition GenericPlatformMath.h:536
static UE_FORCEINLINE_HINT double RoundToDouble(double F)
Definition GenericPlatformMath.h:342
static constexpr void VectorStoreHalf(uint16 *RESTRICT Dst, const float *RESTRICT Src)
Definition GenericPlatformMath.h:134
static UE_FORCEINLINE_HINT float Sin(float Value)
Definition GenericPlatformMath.h:521
static UE_FORCEINLINE_HINT float Tanh(float Value)
Definition GenericPlatformMath.h:545
static UE_FORCEINLINE_HINT double FloorToFloat(double F)
Definition GenericPlatformMath.h:301
static UE_FORCEINLINE_HINT float Exp2(float Value)
Definition GenericPlatformMath.h:492
static int64 FloorToInt64(double F)
Definition GenericPlatformMath.h:270
static UE_FORCEINLINE_HINT double Tanh(double Value)
Definition GenericPlatformMath.h:546
static UE_FORCEINLINE_HINT double CeilToDouble(double F)
Definition GenericPlatformMath.h:394
static UE_FORCEINLINE_HINT double FloorToDouble(double F)
Definition GenericPlatformMath.h:296
static UE_FORCEINLINE_HINT float Pow(float A, float B)
Definition GenericPlatformMath.h:555
static constexpr uint32 MortonCode3(uint32 x)
Definition GenericPlatformMath.h:888
static UE_FORCEINLINE_HINT double Pow(double A, double B)
Definition GenericPlatformMath.h:556
static constexpr UE_FORCEINLINE_HINT float FloatSelect(float Comparand, float ValueGEZero, float ValueLTZero)
Definition GenericPlatformMath.h:923
static UE_FORCEINLINE_HINT int32 FloorToInt(float F)
Definition GenericPlatformMath.h:277
static UE_FORCEINLINE_HINT int32 RoundToInt32(double F)
Definition GenericPlatformMath.h:315
static UE_FORCEINLINE_HINT double Modf(const double InValue, double *OutIntPart)
Definition GenericPlatformMath.h:478
static int64 CeilToInt64(double F)
Definition GenericPlatformMath.h:369
static constexpr UE_FORCEINLINE_HINT int32 TruncToInt32(double F)
Definition GenericPlatformMath.h:216
static UE_FORCEINLINE_HINT float InvSqrtEst(float F)
Definition GenericPlatformMath.h:564
static UE_FORCEINLINE_HINT int32 CeilToInt(float F)
Definition GenericPlatformMath.h:376
static CORE_API int32 GetRandSeed()
Definition GenericPlatformMath.cpp:17
static UE_FORCEINLINE_HINT double CeilToFloat(double F)
Definition GenericPlatformMath.h:399
static UE_FORCEINLINE_HINT double CopySign(double X, double Y)
Definition GenericPlatformMath.h:569
static constexpr UE_FORCEINLINE_HINT uint32 CountTrailingZerosConstExpr(uint32 Value)
Definition GenericPlatformMath.h:763
static constexpr UE_FORCEINLINE_HINT T Abs(const T A)
Definition GenericPlatformMath.h:949
static UE_FORCEINLINE_HINT void RandInit(int32 Seed)
Definition GenericPlatformMath.h:633
static constexpr uint64 FloorLog2_64(uint64 Value)
Definition GenericPlatformMath.h:683
static UE_FORCEINLINE_HINT bool IsNegativeOrNegativeZero(double A)
Definition GenericPlatformMath.h:597
static T Min(const TArray< T > &Values)
Definition GenericPlatformMath.h:1019
RESOLVE_FLOAT_AMBIGUITY_2_ARGS(LogX)
static UE_FORCEINLINE_HINT float Modf(const float InValue, float *OutIntPart)
Definition GenericPlatformMath.h:467
static constexpr int32 CountBits(uint64 Bits)
Definition GenericPlatformMath.h:1168
static UE_FORCEINLINE_HINT int64 RoundToInt64(double F)
Definition GenericPlatformMath.h:319
static constexpr void WideVectorLoadHalf(float *RESTRICT Dst, const uint16 *RESTRICT Src)
Definition GenericPlatformMath.h:142
static UE_FORCEINLINE_HINT float TruncToFloat(float F)
Definition GenericPlatformMath.h:233
static UE_FORCEINLINE_HINT double Fractional(double Value)
Definition GenericPlatformMath.h:440
RESOLVE_FLOAT_AMBIGUITY_2_ARGS(Atan2)
static constexpr UE_FORCEINLINE_HINT int32 TruncToInt32(float F)
Definition GenericPlatformMath.h:212
static constexpr UE_FORCEINLINE_HINT uint64 FloorLog2NonZero_64(uint64 Value)
Definition GenericPlatformMath.h:696
static int32 FloorToInt32(double F)
Definition GenericPlatformMath.h:264
static constexpr uint32 ReverseMortonCode2(uint32 x)
Definition GenericPlatformMath.h:866
static UE_FORCEINLINE_HINT bool IsFinite(float A)
Definition GenericPlatformMath.h:583
static bool AddAndCheckForOverflow(IntType A, IntType B, IntType &OutResult)
Definition GenericPlatformMath.h:1188
RESOLVE_FLOAT_AMBIGUITY_2_ARGS(Pow)
static constexpr UE_FORCEINLINE_HINT uint64 CountTrailingZeros64ConstExpr(uint64 Value)
Definition GenericPlatformMath.h:791
static UE_FORCEINLINE_HINT float Cos(float Value)
Definition GenericPlatformMath.h:530
static UE_FORCEINLINE_HINT int64 CeilToInt(double F)
Definition GenericPlatformMath.h:377
static UE_FORCEINLINE_HINT double Loge(double Value)
Definition GenericPlatformMath.h:496
static UE_FORCEINLINE_HINT float LogX(float Base, float Value)
Definition GenericPlatformMath.h:498
static int32 CeilToInt32(float F)
Definition GenericPlatformMath.h:357
static UE_FORCEINLINE_HINT double Asin(double Value)
Definition GenericPlatformMath.h:525
static UE_FORCEINLINE_HINT float Log2(float Value)
Definition GenericPlatformMath.h:503
static constexpr uint32 MortonCode2(uint32 x)
Definition GenericPlatformMath.h:844
static UE_FORCEINLINE_HINT double InvSqrt(double F)
Definition GenericPlatformMath.h:561
static constexpr uint64 ReverseMortonCode2_64(uint64 x)
Definition GenericPlatformMath.h:876
static UE_FORCEINLINE_HINT bool IsNegative(float A)
Definition GenericPlatformMath.h:615
static constexpr T Max(T A, OtherTypes... Others)
Definition GenericPlatformMath.h:974
static UE_FORCEINLINE_HINT double Frac(double Value)
Definition GenericPlatformMath.h:456
static constexpr uint64 CeilLogTwo64(uint64 Arg)
Definition GenericPlatformMath.h:807
static constexpr UE_FORCEINLINE_HINT double FloatSelect(double Comparand, double ValueGEZero, double ValueLTZero)
Definition GenericPlatformMath.h:942
static constexpr uint64 MortonCode2_64(uint64 x)
Definition GenericPlatformMath.h:854
static UE_FORCEINLINE_HINT double Cosh(double Value)
Definition GenericPlatformMath.h:537
static UE_FORCEINLINE_HINT double Sqrt(double Value)
Definition GenericPlatformMath.h:553
static UE_FORCEINLINE_HINT float Sqrt(float Value)
Definition GenericPlatformMath.h:552
static float FRand()
Definition GenericPlatformMath.h:636
static constexpr void StoreHalf(uint16 *Ptr, float Value)
Definition GenericPlatformMath.h:69
static bool SubtractAndCheckForOverflow(IntType A, IntType B, IntType &OutResult)
Definition GenericPlatformMath.h:1235
static CORE_API float Atan2(float Y, float X)
Definition GenericPlatformMath.cpp:33
static UE_FORCEINLINE_HINT int32 RoundToInt32(float F)
Definition GenericPlatformMath.h:311
static UE_FORCEINLINE_HINT float CopySign(float X, float Y)
Definition GenericPlatformMath.h:568
static constexpr UE_FORCEINLINE_HINT int64 TruncToInt64(double F)
Definition GenericPlatformMath.h:220
static UE_FORCEINLINE_HINT double Tan(double Value)
Definition GenericPlatformMath.h:540
static UE_FORCEINLINE_HINT double Exp(double Value)
Definition GenericPlatformMath.h:489
static UE_FORCEINLINE_HINT double Sin(double Value)
Definition GenericPlatformMath.h:522
static constexpr UE_FORCEINLINE_HINT T Sign(const T A)
Definition GenericPlatformMath.h:956
static UE_FORCEINLINE_HINT float Fractional(float Value)
Definition GenericPlatformMath.h:435
static T Max(const TArray< T > &Values, int32 *MaxIndex)
Definition GenericPlatformMath.h:1108
static constexpr void VectorLoadHalf(float *RESTRICT Dst, const uint16 *RESTRICT Src)
Definition GenericPlatformMath.h:126
static float AsFloat(uint32 U)
Definition GenericPlatformMath.h:185
static constexpr uint64 CountTrailingZeros64(uint64 Value)
Definition GenericPlatformMath.h:775
static UE_FORCEINLINE_HINT float Sinh(float Value)
Definition GenericPlatformMath.h:527
static constexpr uint32 CountTrailingZeros(uint32 Value)
Definition GenericPlatformMath.h:747
static UE_FORCEINLINE_HINT int64 RoundToInt(double F)
Definition GenericPlatformMath.h:325
RESOLVE_FLOAT_AMBIGUITY_2_ARGS(Fmod)
static bool MultiplyAndCheckForOverflow(IntType A, IntType B, IntType &OutResult)
Definition GenericPlatformMath.h:1276
MIX_SIGNED_INTS_2_ARGS_CONSTEXPR(Max)
static UE_FORCEINLINE_HINT double Exp2(double Value)
Definition GenericPlatformMath.h:493
static UE_FORCEINLINE_HINT double Log2(double Value)
Definition GenericPlatformMath.h:505
static constexpr uint64 CountLeadingZeros64(uint64 Value)
Definition GenericPlatformMath.h:734
static UE_FORCEINLINE_HINT double TruncToFloat(double F)
Definition GenericPlatformMath.h:248
static constexpr UE_FORCEINLINE_HINT int64 TruncToInt(double F)
Definition GenericPlatformMath.h:226
static UE_FORCEINLINE_HINT bool IsNegativeDouble(double A)
Definition GenericPlatformMath.h:609
static UE_FORCEINLINE_HINT double Sinh(double Value)
Definition GenericPlatformMath.h:528
static UE_FORCEINLINE_HINT float Tan(float Value)
Definition GenericPlatformMath.h:539
static constexpr uint32 CountLeadingZeros(uint32 Value)
Definition GenericPlatformMath.h:721
static T Max(const TArray< T > &Values)
Definition GenericPlatformMath.h:1081
static constexpr uint8 CountLeadingZeros8(uint8 Value)
Definition GenericPlatformMath.h:708
static UE_FORCEINLINE_HINT int32 Rand32()
Definition GenericPlatformMath.h:630
static constexpr uint32 FloorLog2(uint32 Value)
Definition GenericPlatformMath.h:659
static constexpr uint32 ReverseMortonCode3(uint32 x)
Definition GenericPlatformMath.h:899
static UE_FORCEINLINE_HINT double Acos(double Value)
Definition GenericPlatformMath.h:534
static UE_FORCEINLINE_HINT double Atan(double Value)
Definition GenericPlatformMath.h:543
static UE_FORCEINLINE_HINT float CeilToFloat(float F)
Definition GenericPlatformMath.h:384
static UE_FORCEINLINE_HINT float RoundToFloat(float F)
Definition GenericPlatformMath.h:332
static UE_FORCEINLINE_HINT float FloorToFloat(float F)
Definition GenericPlatformMath.h:286
static UE_FORCEINLINE_HINT double TruncToDouble(double F)
Definition GenericPlatformMath.h:243
static constexpr void GetMinMax(const T &A, const T &B, T &OutMin, T &OutMax)
Definition GenericPlatformMath.h:1142
static UE_FORCEINLINE_HINT double InvSqrtEst(double F)
Definition GenericPlatformMath.h:565
static constexpr float LoadHalf(const uint16 *Ptr)
Definition GenericPlatformMath.h:35
static UE_FORCEINLINE_HINT float Atan(float Value)
Definition GenericPlatformMath.h:542
static int64 RoundToNearestTiesToEven(double F)
Definition GenericPlatformMath.h:410
RESOLVE_FLOAT_AMBIGUITY_2_ARGS(CopySign)
static CORE_API float SRand()
Definition GenericPlatformMath.cpp:22
static double AsFloat(uint64 U)
Definition GenericPlatformMath.h:198
static UE_FORCEINLINE_HINT double RoundToFloat(double F)
Definition GenericPlatformMath.h:347
static UE_FORCEINLINE_HINT int32 Rand()
Definition GenericPlatformMath.h:627
static UE_FORCEINLINE_HINT float Acos(float Value)
Definition GenericPlatformMath.h:533
static constexpr UE_FORCEINLINE_HINT T Min(T A, T B)
Definition GenericPlatformMath.h:985
static int32 CeilToInt32(double F)
Definition GenericPlatformMath.h:363
static int32 FloorToInt32(float F)
Definition GenericPlatformMath.h:258
static UE_FORCEINLINE_HINT bool IsNaN(float A)
Definition GenericPlatformMath.h:573
static constexpr UE_FORCEINLINE_HINT uint32 RoundUpToPowerOfTwo(uint32 Arg)
Definition GenericPlatformMath.h:833
static UE_FORCEINLINE_HINT bool IsFinite(double A)
Definition GenericPlatformMath.h:587
static UE_FORCEINLINE_HINT int32 RoundToInt(float F)
Definition GenericPlatformMath.h:324
static UE_FORCEINLINE_HINT bool IsNegativeOrNegativeZero(float A)
Definition GenericPlatformMath.h:592
static UE_FORCEINLINE_HINT double Cos(double Value)
Definition GenericPlatformMath.h:531
static CORE_API void SRandInit(int32 Seed)
Definition GenericPlatformMath.cpp:12
static UE_FORCEINLINE_HINT double LogX(double Base, double Value)
Definition GenericPlatformMath.h:499
static T Min(const TArray< T > &Values, int32 *MinIndex)
Definition GenericPlatformMath.h:1045
static constexpr UE_FORCEINLINE_HINT uint32 FloorLog2NonZero(uint32 Value)
Definition GenericPlatformMath.h:671
static constexpr uint8 ConstExprCeilLogTwo(SIZE_T Arg)
Definition GenericPlatformMath.h:818
MIX_SIGNED_INTS_2_ARGS_CONSTEXPR(Min)
static constexpr UE_FORCEINLINE_HINT T Max(T A, T B)
Definition GenericPlatformMath.h:963
static constexpr void GetMinMax(T &Min, T &Max)
Definition GenericPlatformMath.h:1160
static UE_FORCEINLINE_HINT float InvSqrt(float F)
Definition GenericPlatformMath.h:560
static constexpr void WideVectorStoreHalf(uint16 *RESTRICT Dst, const float *RESTRICT Src)
Definition GenericPlatformMath.h:148
static UE_FORCEINLINE_HINT bool IsNegativeFloat(float A)
Definition GenericPlatformMath.h:603
static uint64 AsUInt(double D)
Definition GenericPlatformMath.h:172
static UE_FORCEINLINE_HINT float Exp(float Value)
Definition GenericPlatformMath.h:487
static UE_FORCEINLINE_HINT bool IsNaN(double A)
Definition GenericPlatformMath.h:577
static constexpr uint32 CeilLogTwo(uint32 Arg)
Definition GenericPlatformMath.h:800
static UE_FORCEINLINE_HINT float Loge(float Value)
Definition GenericPlatformMath.h:495
static UE_FORCEINLINE_HINT float Frac(float Value)
Definition GenericPlatformMath.h:450
static uint32 AsUInt(float F)
Definition GenericPlatformMath.h:159
static UE_FORCEINLINE_HINT int64 FloorToInt(double F)
Definition GenericPlatformMath.h:278
static UE_FORCEINLINE_HINT float Asin(float Value)
Definition GenericPlatformMath.h:524