FMath::Abs
#include "GenericPlatform/GenericPlatformMath.h"
Access: public
Specifiers: static
Description
Returns the absolute (non-negative) value of A. Works with any signed numeric type via template specialisation, including int32, float, and double.
Signature
template< class T >
static constexpr UE_FORCEINLINE_HINT T Abs(const T A) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | T | The value whose absolute value is returned. | — |
Return Type
T Caveats & Gotchas
- • For floating-point types, FMath::Abs does not handle NaN or negative zero specially — results are consistent with std::abs behaviour.
- • For integer types, FMath::Abs(INT_MIN) is undefined behaviour — there is no positive representation of INT_MIN in two's complement.
- • For FVector, use FVector::GetAbs() to get a component-wise absolute value, not FMath::Abs which only accepts scalars.
Example
Guard a distance check and compute error magnitude C++
float Delta = TargetValue - CurrentValue;
if (FMath::Abs(Delta) > Tolerance)
{
ApplyCorrection(Delta);
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?