Unity - Scripting API: Mathf.Epsilon
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.
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.
public static float Epsilon;
Description
The smallest positive non-zero value that a float can represent. Using Mathf.Epsilon as a delta for equality makes the comparison effectively identical to exact equality on normal-range numbers. For an approximately equal value, use Mathf.Approximately or a tolerance that reflects your data’s scale, typically a combination of absolute and relative tolerances.
Operations with Epsilon follow these rules:
- anyValue + Epsilon = anyValue
- anyValue - Epsilon = anyValue
- 0 + Epsilon = Epsilon
- 0 - Epsilon = -Epsilon
A value between any number and Epsilon will result in an arbitrary number due to loss of trailing digits.
using UnityEngine;public class Example : MonoBehaviour { // Avoid division by (near) zero using Mathf.Epsilon as a zero guard. float SafeDivide(float numerator, float denominator) { if (Mathf.Abs(denominator) <= Mathf.Epsilon) return 0f; // or handle appropriately
return numerator / denominator; } }