Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Epsilon

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.
Read time 1 minuteLast updated 5 days ago

Definition

  • Type: Field
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public static readonly float Epsilon

Remarks

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.

Examples

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