Abs
Returns the absolute value of f.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
Abs(float)
Returns the absolute value of .
fpublic static float Abs(float f)
Parameters
Real number whose absolute value will be returned.
Returns
Type | Description |
|---|---|
| float | Non-negative value of |
Remarks
For a real number , its absolute value is defined as the non-negative value of without regard to its sign.
ffAdditional Resources: Mathf.Sign.
Examples
using UnityEngine;public class Example : MonoBehaviour{ void Start() { // Prints 10 Debug.Log(Mathf.Abs(-10.0f)); // Prints 0 Debug.Log(Mathf.Abs(0.0f)); // Prints 10 Debug.Log(Mathf.Abs(10.0f)); }}
Abs(int)
Returns the absolute value of .
valuepublic static int Abs(int value)
Parameters
Integer number whose absolute value will be returned.
Returns
Type | Description |
|---|---|
| int | Non-negative value of |
Remarks
For an integer number , its absolute value is defined as its non-negative value without regard to its sign.
valueAdditional Resources: Mathf.Sign.
Examples
using UnityEngine;public class Example : MonoBehaviour{ void Start() { // Prints 10 Debug.Log(Mathf.Abs(-10)); // Prints 0 Debug.Log(Mathf.Abs(0)); // Prints 10 Debug.Log(Mathf.Abs(10)); }}