Utils.AreFloatsEqualAbsoluteError

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static bool AreFloatsEqualAbsoluteError(float expected, float actual, float allowedAbsoluteError);

Parameters

expectedThe expected value.
actualActual value to be compared with the expected value.
allowedAbsoluteErrorThe permissible tolerance.

Returns

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

Description

Compares two float values for equality.

This method compares two floating point numbers for equality under the given absolute tolerance.

using UnityEngine.TestTools.Utils;

using NUnit.Framework;

[TestFixture]

class UtilsTest { [Test]

public void FloatsAreAbsoluteEqual() { float expected = 0f;

float actual = 10e-6f;

float error = 10e-5f;

Assert.That(Utils.AreFloatsEqualAbsoluteError(expected, actual, error), Is.True); } }

Did you find this page useful? Please give it a rating: