pow

(PHP 4, PHP 5, PHP 7, PHP 8)

pow指數(shù)表達(dá)式

說(shuō)明

pow(number $base, number $exp): number

返回 baseexp 次方的冪。如果可能,本函數(shù)會(huì)返回 integer。

參數(shù)

base

The base to use

exp

指數(shù)

返回值

baseexp 次方的冪。 If both arguments are non-negative integers and the result can be represented as an integer, the result will be returned with integer type, otherwise it will be returned as a float.

更新日志

版本 說(shuō)明
4.2.0 如果不能計(jì)算冪,將發(fā)出一條警告,pow() 將返回 false。pow() 開(kāi)始不產(chǎn)生任何的警告。
4.0.6 如果可能函數(shù)現(xiàn)在會(huì)返回 integer 的結(jié)果,之前 總是返回 float,F(xiàn)or older versions, you may receive a bogus result for complex numbers.

范例

示例 #1 pow() 的一些例子

<?php

var_dump
(pow(28)); // int(256)
echo pow(-120); // 1
echo pow(00); // 1

echo pow(-15.5); // PHP >4.0.6  NAN
echo pow(-15.5); // PHP <=4.0.6 1.#IND
?>

注釋

注意:

本函數(shù)會(huì)轉(zhuǎn)換所有輸入為數(shù)字,即使是非標(biāo)量值,會(huì)導(dǎo)致怪異的(weird)結(jié)果。

參見(jiàn)

  • exp() - 計(jì)算 e 的指數(shù)
  • sqrt() - 平方根
  • bcpow() - 任意精度數(shù)字的乘方
  • gmp_pow() - Raise number into power