Abs
Returns the absolute value of f.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
Abs(float)
Returns the absolute value of f.
public static float Abs(float f)
Parameters
Returns
Type | Description |
|---|---|
| float |
Examples
using UnityEngine;public class ScriptExample : 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)); }}