Version: 2022.3
public static float Epsilon ;

描述

微小浮点值(只读)。

浮点数可以与零相差的最小值。

采用以下规则: 任何值 + Epsilon = 任何值 任何值 - Epsilon = 任何值 0 + Epsilon = Epsilon 0 - Epsilon = -Epsilon 介于任何数字与 Epsilon 之间的值会产生任意数字,因为存在 截断误差。

另请参阅:Mathf.Approximately

using UnityEngine;

public class Example : MonoBehaviour { // Compares two floating point numbers and return true if they are the same number. // See also Mathf.Approximately, which compares floating point numbers so you dont have // to create a function to compare them.

bool isEqual(float a, float b) { if (a >= b - Mathf.Epsilon &amp;&amp; a <= b + Mathf.Epsilon) { return true; } else { return false; } } }