FMath::IsNearlyEqualByULP

Check if two floating point numbers are nearly equal to within specific number of units of last place (ULP).

Windows
MacOS
Linux

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Math/UnrealMathUtility.h

Include

#include "Math/UnrealMathUtility.h"

Syntax

static bool IsNearlyEqualByULP
(
    double A,
    double B,
    int32 MaxUlps
)

Remarks

Check if two floating point numbers are nearly equal to within specific number of units of last place (ULP). A single ULP difference between two floating point numbers means that they have an adjacent representation and that no other floating point number can be constructed to fit between them. This enables making consistent comparisons based on representational distance between floating point numbers, regardless of their magnitude.

Note: Since IEEE 754 floating point operations are guaranteed to be exact to 0.5 ULP, a value of 4 ought to be sufficient for all but the most complex float operations.

Returns

true if the two values are nearly equal.

Parameters

Parameter

Description

A

First number to compare

B

Second number to compare

MaxUlps

The maximum ULP distance by which neighboring floating point numbers are allowed to differ.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss