Version: 2018.1
public static bool AreFloatsEqual (float expected, float actual, float allowedRelativeError);

パラメーター

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

戻り値

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

説明

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); } }