FGenericPlatformMath

Generic implementation for most platforms

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

FGenericPlatformMath

FClangPlatformMath

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/GenericPlatform/GenericPlatformMath.h

Include

#include "GenericPlatform/GenericPlatformMath.h"

Syntax

struct FGenericPlatformMath

Remarks

Generic implementation for most platforms

Functions

Name Description

Public function

double

 

Abs

(
    const double A
)

Public function

float

 

Abs

(
    const float A
)

Float specialization

Public function Static

constexpr T

 

Abs

(
    const T A
)

Computes absolute value in a generic way

Public function Static

double

 

Acos

(
    double Value
)

Public function Static

float

 

Acos

(
    float Value
)

Public function Static

float

 

AsFloat

(
    uint32 U
)

Performs a bit cast of the given unsigned int to float of the same bit width.

Public function Static

double

 

AsFloat

(
    uint64 U
)

Performs a bit cast of the given unsigned int to float of the same bit width.

Public function Static

float

 

Asin

(
    float Value
)

Public function Static

double

 

Asin

(
    double Value
)

Public function Static

uint32

 

AsUInt

(
    float F
)

Performs a bit cast of the given float to an unsigned int of the same bit width.

Public function Static

uint64

 

AsUInt

(
    double F
)

Performs a bit cast of the given double to an unsigned int of the same bit width.

Public function Static

float

 

Atan

(
    float Value
)

Public function Static

double

 

Atan

(
    double Value
)

Public function Static

float

 

Atan2

(
    float Y,
    float X
)

Public function Static

double

 

Atan2

(
    double Y,
    double X
)

Public function Static

uint32

 

CeilLogTwo

(
    uint32 Arg
)

Returns smallest N such that (1<=Arg.

CeilLogTwo(0)=0 because (1<<0)=1 >= 0.

Public function Static

uint64

 

CeilLogTwo64

(
    uint64 Arg
)

Public function Static

double

 

CeilToDouble

(
    double F
)

Converts a double to the nearest greater or equal integer.

Public function Static

double

 

CeilToFloat

(
    double F
)

Public function Static

float

 

CeilToFloat

(
    float F
)

Converts a float to the nearest greater or equal integer.

Public function Static

int32

 

CeilToInt

(
    double F
)

Public function Static

int32

 

CeilToInt

(
    float F
)

Converts a float to the nearest greater or equal integer.

Public function Static

int64

 

CeilToInt64

(
    double F
)

Public function Static

double

 

Cos

(
    double Value
)

Public function Static

float

 

Cos

(
    float Value
)

Public function Static

int32

 

CountBits

(
    uint64 Bits
)

Public function Static

uint32

 

CountLeadingZeros

(
    uint32 Value
)

Counts the number of leading zeros in the bit representation of the 32-bit value

Public function Static

uint64

 

CountLeadingZeros64

(
    uint64 Value
)

Counts the number of leading zeros in the bit representation of the 64-bit value

Public function Static

uint8

 

CountLeadingZeros8

(
    uint8 Value
)

Counts the number of leading zeros in the bit representation of the 8-bit value

Public function Static

uint32

 

CountTrailingZeros

(
    uint32 Value
)

Counts the number of trailing zeros in the bit representation of the value

Public function Static

uint64

 

CountTrailingZeros64

(
    uint64 Value
)

Counts the number of trailing zeros in the bit representation of the value

Public function Static

double

 

Exp

(
    double Value
)

Public function Static

float

 

Exp

(
    float Value
)

Returns e^Value.

Public function Static

double

 

Exp2

(
    double Value
)

Public function Static

float

 

Exp2

(
    float Value
)

Returns 2^Value.

Public function Static

constexpr fl...

 

FloatSelect

(
    float Comparand,
    float ValueGEZero,
    float ValueLTZero
)

Returns value based on comparand.

Public function Static

constexpr do...

 

FloatSelect

(
    double Comparand,
    double ValueGEZero,
    double ValueLTZero
)

Returns value based on comparand.

Public function Static

uint32

 

FloorLog2

(
    uint32 Value
)

Computes the base 2 logarithm for an integer value that is greater than 0.

Public function Static

uint64

 

FloorLog2_64

(
    uint64 Value
)

Computes the base 2 logarithm for a 64-bit value that is greater than 0.

Public function Static

double

 

FloorToDouble

(
    double F
)

Converts a double to a less or equal integer.

Public function Static

float

 

FloorToFloat

(
    float F
)

Converts a float to the nearest less or equal integer.

Public function Static

double

 

FloorToFloat

(
    double F
)

Public function Static

int32

 

FloorToInt

(
    float F
)

Converts a float to a nearest less or equal integer.

Public function Static

int32

 

FloorToInt

(
    double F
)

Public function Static

int64

 

FloorToInt64

(
    double F
)

Public function Static

double

 

Fmod

(
    double X,
    double Y
)

Returns the floating-point remainder of X / Y Warning: Always returns remainder toward 0, not toward the smaller multiple of Y.

Public function Static

float

 

Fmod

(
    float X,
    float Y
)

Returns the floating-point remainder of X / Y Warning: Always returns remainder toward 0, not toward the smaller multiple of Y.

Public function Static

float

 

Frac

(
    float Value
)

Returns the fractional part of a float.

Public function Static

double

 

Frac

(
    double Value
)

Public function Static

double

 

Fractional

(
    double Value
)

Public function Static

float

 

Fractional

(
    float Value
)

Returns signed fractional part of a float.

Public function Static

float

 

FRand()

Returns a random float between 0 and 1, inclusive.

Public function Static

int32

 

GetRandSeed()

Returns the current seed for SRand().

Public function Static

float

 

InvSqrt

(
    float F
)

Computes a fully accurate inverse square root

Public function Static

double

 

InvSqrt

(
    double F
)

Public function Static

float

 

InvSqrtEst

(
    float F
)

Computes a faster but less accurate inverse square root

Public function Static

double

 

InvSqrtEst

(
    double F
)

Public function Static

bool

 

IsFinite

(
    float A
)

Return true if value is finite (not NaN and not Infinity).

Public function Static

bool

 

IsFinite

(
    double A
)

Public function Static

bool

 

IsNaN

(
    float A
)

Return true if value is NaN (not a number).

Public function Static

bool

 

IsNaN

(
    double A
)

Public function Static

bool

 

IsNegative

(
    float A
)

Public function Static

bool

 

IsNegative

(
    double A
)

Public function Static

float

 

LoadHalf

(
    const uint16* Ptr
)

https://gist.github.com/rygorous/2156668

Public function Static

float

 

Log2

(
    float Value
)

1.0 / Loge(2) = 1.4426950f

Public function Static

double

 

Log2

(
    double Value
)

1.0 / Loge(2) = 1.442695040888963387

Public function Static

float

 

Loge

(
    float Value
)

Public function Static

double

 

Loge

(
    double Value
)

Public function Static

float

 

LogX

(
    float Base,
    float Value
)

Public function Static

double

 

LogX

(
    double Base,
    double Value
)

Public function Static

constexpr T

 

Max

(
    const T A,
    const T B
)

Returns higher value in a generic way

Public function Static

constexpr do...

 

Max

(
    const double A,
    const float B
)

LWC_TODO: Simplify code refactoring to avoid double/float mismatches. Should not ship?

Public function Static

T

 

Max

(
    const TArray< T >& Values,
    int32* MaxIndex
)

Max of Array

Public function

VectorRegist...

 

Max

(
    const VectorRegister4Float A,
    const VectorRegister4Float B
)

Returns the larger of the two values (operates on each component individually)

Public function

VectorRegist...

 

Max

(
    const VectorRegister4Double A,
    const VectorRegister4Double B
)

Public function Static

constexpr do...

 

Max

(
    const float A,
    const double B
)

Public function

VectorRegist...

 

Min

(
    const VectorRegister4Double A,
    const VectorRegister4Double B
)

Public function Static

constexpr T

 

Min

(
    const T A,
    const T B
)

Returns lower value in a generic way

Public function Static

constexpr do...

 

Min

(
    const double A,
    const float B
)

Public function Static

constexpr do...

 

Min

(
    const float A,
    const double B
)

Public function Static

T

 

Min

(
    const TArray< T >& Values,
    int32* MinIndex
)

Min of Array

Public function

VectorRegist...

 

Min

(
    const VectorRegister4Float A,
    const VectorRegister4Float B
)

Returns the smaller of the two values (operates on each component individually)

Public function Static

double

 

Modf

(
    const double InValue,
    double* OutIntPart
)

Breaks the given value into an integral and a fractional part.

Public function Static

float

 

Modf

(
    const float InValue,
    float* OutIntPart
)

Breaks the given value into an integral and a fractional part.

Public function Static

uint32

 

MortonCode2

(
    uint32 x
)

Spreads bits to every other.

Public function Static

uint64

 

MortonCode2_64

(
    uint64 x
)

Public function Static

uint32

 

MortonCode3

(
    uint32 x
)

Spreads bits to every 3rd.

Public function Static

float

 

Pow

(
    float A,
    float B
)

Public function Static

double

 

Pow

(
    double A,
    double B
)

Public function Static

int32

 

Rand()

Returns a random integer between 0 and RAND_MAX, inclusive

Public function Static

void

 

RandInit

(
    int32 Seed
)

Seeds global random number functions Rand() and FRand()

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    CeilToFloat
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Fractional
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Frac
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Loge
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Exp2
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Log2
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Asin
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Sinh
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Cos
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Acos
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Tan
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Atan
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Sqrt
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    InvSqrt
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    InvSqrtEst
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    Exp
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    RoundToFloat
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    FloorToFloat
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY

(
    TruncToFloat
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY_2_ARGS

(
    Pow
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY_2_ARGS

(
    Atan2
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY_2_ARGS

(
    Fmod
)

Public function

 

RESOLVE_FLOAT_AMBIGUITY_2_ARGS

(
    LogX
)

Public function

 

RESOLVE_FLOAT_TO_TYPE_AMBIGUITY

(
    CeilToInt,
    int32
)

Public function

 

RESOLVE_FLOAT_TO_TYPE_AMBIGUITY

(
    FloorToInt,
    int32
)

Public function

 

RESOLVE_FLOAT_TO_TYPE_AMBIGUITY

(
    TruncToInt,
    int32
)

Public function Static

uint32

 

ReverseMortonCode2

(
    uint32 x
)

Reverses MortonCode2. Compacts every other bit to the right.

Public function Static

uint64

 

ReverseMortonCode2_64

(
    uint64 x
)

Public function Static

uint32

 

ReverseMortonCode3

(
    uint32 x
)

Reverses MortonCode3. Compacts every 3rd bit to the right.

Public function Static

double

 

RoundToDouble

(
    double F
)

Converts a double to the nearest integer. Rounds up when the fraction is .5

Public function Static

double

 

RoundToFloat

(
    double F
)

Public function Static

float

 

RoundToFloat

(
    float F
)

Converts a float to the nearest integer. Rounds up when the fraction is .5

Public function Static

int32

 

RoundToInt

(
    float F
)

Converts a float to the nearest integer. Rounds up when the fraction is .5

Public function Static

uint32

 

RoundUpToPowerOfTwo

(
    uint32 Arg
)

Public function Static

uint64

 

RoundUpToPowerOfTwo64

(
    uint64 V
)

Public function Static

constexpr T

 

Sign

(
    const T A
)

Returns 1, 0, or -1 depending on relation of T to 0

Public function Static

double

 

Sin

(
    double Value
)

Public function Static

float

 

Sin

(
    float Value
)

Public function Static

double

 

Sinh

(
    double Value
)

Public function Static

float

 

Sinh

(
    float Value
)

Public function Static

float

 

Sqrt

(
    float Value
)

Public function Static

double

 

Sqrt

(
    double Value
)

Public function Static

float

 

SRand()

Returns a seeded random float in the range [0,1), using the seed from SRandInit().

Public function Static

void

 

SRandInit

(
    int32 Seed
)

Seeds future calls to SRand()

Public function Static

void

 

StoreHalf

(
    uint16* Ptr,
    float Value
)

https://gist.github.com/rygorous/2156668 float_to_half_fast3_rtne

Public function Static

float

 

Tan

(
    float Value
)

Public function Static

double

 

Tan

(
    double Value
)

Public function Static

double

 

TruncToDouble

(
    double F
)

Converts a double to an integer value with truncation towards zero.

Public function Static

float

 

TruncToFloat

(
    float F
)

Converts a float to an integer value with truncation towards zero.

Public function Static

double

 

TruncToFloat

(
    double F
)

Public function Static

constexpr in...

 

TruncToInt

(
    double F
)

Public function Static

constexpr in...

 

TruncToInt

(
    float F
)

Converts a float to an integer with truncation towards zero.

Public function Static

void

 

VectorLoadHalf

(
    float*restrict Dst,
    const uint16*
restrict Src
)

Public function Static

void

 

VectorStoreHalf

(
    uint16*restrict Dst,
    const float*
restrict Src
)

Public function Static

void

 

WideVectorLoadHalf

(
    float*restrict Dst,
    const uint16*
restrict Src
)

Public function Static

void

 

WideVectorStoreHalf

(
    uint16*restrict Dst,
    const float*
restrict Src
)

Classes

Name

Description

Public struct

TIsSameOrNotFP

Temporary support for ambiguities to simplify UE4 -> UE5 upgrades - falls back to float variant.

Constants

Name

Description

TIsAmbiguous

Deprecated Functions

Name Description

Public function Static

bool

 

IsNegativeDouble

(
    double A
)

Use IsNegative here.

Public function Static

bool

 

IsNegativeFloat

(
    float A
)

Use IsNegative here.