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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961