UKismetMathLibrary::NearlyEqual_FloatFloat
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns true if the absolute difference between A and B is less than ErrorTolerance (|A - B| < ErrorTolerance). The correct way to compare computed floating-point values for equality.
Caveats & Gotchas
- • The default tolerance (1e-6) is an absolute epsilon, not a relative one — it works well for values near 1.0 but is too tight for large values (e.g., world-space coordinates in the tens-of-thousands range) and too loose for values near 0. Scale ErrorTolerance to the magnitude of your inputs.
- • This function is not the same as FMath::IsNearlyEqual, which uses a relative epsilon — be aware of which version you need when porting logic between C++ and Blueprint.
Signature
static UE_INL_API bool NearlyEqual_FloatFloat(double A, double B, double ErrorTolerance = 1.e-6); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | double | The first value to compare. | — |
| B | double | The second value to compare. | — |
| ErrorTolerance | double | The maximum absolute difference allowed for the values to be considered equal. | 1.e-6 |
Return Type
bool Example
Check if a lerp result has reached its target C++
double Current = FMath::Lerp(StartVal, TargetVal, Alpha);
if (UKismetMathLibrary::NearlyEqual_FloatFloat(Current, TargetVal, 0.01))
{
bReachedTarget = true;
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?