Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Sign(float)

Returns the mathematical sign of f.
Read time 1 minuteLast updated 6 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public static float Sign(float f)

Parameters

Real number whose sign will be retrieved.

Returns

Type

Description

floatMathematical sign of
f
.

Remarks

Returns either a value of -1 when
f
is negative, or a value of 1 when
f
is 0 or greater. This is different from standard 'Sign' implementations which return 0 whenever
f
equals 0.

Examples

using UnityEngine;public class Example : MonoBehaviour{ void Start() { // Prints -1 Debug.Log(Mathf.Sign(-10)); // Prints 1 Debug.Log(Mathf.Sign(0)); // Prints 1 Debug.Log(Mathf.Sign(10)); }}