Mathf.Approximately with a threshold ?

Hey guys, Is there any function that does like Mathf.Approximately but that I can pass it a threshold, because my value differs for like 0.01 or so and approximately returns false because it must be a smaller difference than that, but I wonder if there is any other function in that already exists that could do thing that I wanna do without writing it manually.

Thanks a lot for your time :slight_smile:

Claude

Although @robertbuโ€™s answer is perfect, hereโ€™s in the form of a method you could use anywhere. Itโ€™s also a little bit faster than using Mathf.Abs()
(Code is in C#)

public static bool FastApproximately(float a, float b, float threshold)
{
    return ((a - b) < 0 ? ((a - b) * -1) : (a - b)) <= threshold;
}

I answer because it is one of top result on google.

public static bool FastApproximately(float a, float b, float threshold)
 {
        if (threshold > 0f)
        {
            return Mathf.Abs(a- b) <= m_Threshold;
        }
        else
        {
            return Mathf.Approximately(a, b);
        }
 }

Is much more readable than the ternary operator used in other answer. Optimizing to this point is counter productive.
Also, in case threshold equals 0, you must use float.Approximately to avoid rounding error.