Utils.AreFloatsEqual

Switch to Manual
public static bool AreFloatsEqual (float expected, float actual, float allowedRelativeError);

Parameters

expectedThe expected value.
actualActual value to be compared with the expected value.
allowedRelativeErrorThe relative error to be used in relative epsilon comparison.

Returns

bool Returns true if the actual value is equaivalent to the expected value.

Description

Relative epsilon comparison of two float values for equality.

This method does the relative epsilon comparison of two floating point numbers for equality. Supply the relative error as the third parameter. The relative error is the absolute error divided by the magnitude of the exact value.

using UnityEngine.TestTools.Utils;

using NUnit.Framework;

[TestFixture]

class UtilsTest { [Test]

public void FloatsAreEqual() { float expected = 10e-8f;

float actual = 0f;

float allowedRelativeError = 10e-6f;

Assert.That(Utils.AreFloatsEqual(expected, actual, allowedRelativeError), Is.True); } }