FMath::IsNearlyEqual
#include "Math/UnrealMathUtility.h"
Access: public
Specifiers: static
Description
Returns true if two floating-point numbers are within a given absolute tolerance of each other. Use instead of == for float comparisons.
Signature
static UE_FORCEINLINE_HINT bool IsNearlyEqual(float A, float B, float ErrorTolerance = UE_SMALL_NUMBER) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | float | First value to compare. | — |
| B | float | Second value to compare. | — |
| ErrorTolerance | float | Maximum allowed absolute difference. Defaults to UE_SMALL_NUMBER (1e-8). | UE_SMALL_NUMBER |
Return Type
bool Caveats & Gotchas
- • Uses absolute tolerance, not relative. For values with large magnitude (e.g. world-space coordinates in large worlds), UE_SMALL_NUMBER may be too tight — scale your tolerance to the expected magnitude.
- • The default tolerance UE_SMALL_NUMBER (1e-8) is very strict. UE_KINDA_SMALL_NUMBER (1e-4) is more appropriate for most gameplay comparisons.
- • Does not handle NaN — if either input is NaN, the result is false (since all comparisons with NaN return false in IEEE 754).
Example
Snap interp result to target and compare angles C++
// Snap to target once close enough (avoids asymptotic drift)
CurrentValue = FMath::FInterpTo(CurrentValue, TargetValue, DeltaTime, 5.0f);
if (FMath::IsNearlyEqual(CurrentValue, TargetValue, 0.1f))
{
CurrentValue = TargetValue;
} See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?