Mathf.Abs

Switch to Manual

Declaration

public static float Abs(float f);

Parameters

f Real number whose absolute value will be returned.

Returns

float Non-negative value of f.

Description

Returns the absolute value of f.

For a real number f, its absolute value is defined as the non-negative value of f without regard to its sign.

Additional resources: Sign.

using UnityEngine;

public class Example : MonoBehaviour { void Start() { // Prints 10 Debug.Log(Mathf.Sign(-10.0f)); // Prints 0 Debug.Log(Mathf.Sign(0.0f)); // Prints 10 Debug.Log(Mathf.Sign(10.0f)); } }

Declaration

public static int Abs(int value);

Parameters

value Integer number whose absolute value will be returned.

Returns

int Non-negative value of value.

Description

Returns the absolute value of value.

For an integer number value, its absolute value is defined as its non-negative value without regard to its sign.

Additional resources: Sign.

using UnityEngine;

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

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