LanguageEnglish
  • C#

Mathf.Pow

Switch to Manual

Declaration

public static float Pow(float f, float p);

Parameters

f Base of the exponentiation operation.
p Exponent of the exponentiation operation.

Returns

float Result of the exponentiation operation.

Description

Returns the result of raising f to the power p.

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 f by itself p times. - For fractional numbers in the range (0, 1), the result of exponentiation is equal to the result of computing the n-th root of f, with n being 1/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 f to the absolute (non-signed) value of p.

Additional resources: Log.

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

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961