Mathf.Sign

Switch to Manual

Declaration

public static float Sign(float f);

Parameters

f Real number whose sign will be retrieved.

Returns

float Mathematical sign of f.

Description

Returns the mathematical sign of f.

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.

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

Did you find this page useful? Please give it a rating: