Pow(float, float)
Returns the result of raising f to the power p.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
public static float Pow(float f, float p)
Parameters
Returns
Type | Description |
|---|---|
| float | Result of the exponentiation operation. |
Remarks
The behaviour of exponentiation varies greatly depending on the sign and range of the exponent :
p- For real numbers in the range [1, ∞], the result of exponentiation is equal to the result of multiplying by itself
ftimes.p - For fractional numbers in the range (0, 1), the result of exponentiation is equal to the result of computing the n-th root of , with n being 1/
f.p - For the value 0, you will get the value 1.
- For real numbears in the range [-∞, 0), the result of exponentiation is equal to the result of diving 1 by the result of raising to the absolute (non-signed) value of
f.p
Additional Resources: Mathf.Log.
Examples
using UnityEngine;public class Example : MonoBehaviour{ void Start() { // Prints Infinity Debug.Log(Mathf.Pow(2, Mathf.Infinity)); // Prints 256 Debug.Log(Mathf.Pow(2, 8)); // Prints 2 Debug.Log(Mathf.Pow(2, 1)); // Prints 1.414214 Debug.Log(Mathf.Pow(2, 0.5f)); // Prints 1 Debug.Log(Mathf.Pow(2, 0)); // Prints 0.7071068 Debug.Log(Mathf.Pow(2, -0.5f)); // Prints 0.5 Debug.Log(Mathf.Pow(2, -1)); // Prints 0.00390625 Debug.Log(Mathf.Pow(2, -8)); // Prints 0 Debug.Log(Mathf.Pow(2, -Mathf.Infinity)); }}