(PHP 4, PHP 5, PHP 7, PHP 8)
bcpow — 任意精度数値をべき乗する
num
基数を表す文字列。
exponent
指数を表す文字列。
指数が整数でない場合、値は切り捨てられます。
正しい指数の範囲はプラットフォーム依存ですが、
少なくとも -2147483648
から
2147483647
までの範囲を持ちます。
scale
null
, it will default to the default scale set with bcscale(),
or fallback to the value of the
bcmath.scale
INI directive.
結果を文字列で返します。
This function throws a ValueError in the following cases:
num
or exponent
is not a well-formed BCMath numeric stringexponent
has a fractional partexponent
or scale
is outside the valid range
This function throws a DivisionByZeroError exception if num
is 0
and exponent
is a negative value.
バージョン | 説明 |
---|---|
8.4.0 |
Negative powers of 0 previously returned 0, but now throw a DivisionByZeroError
exception.
|
8.0.0 |
When exponent has a fractional part, it now throws a ValueError
instead of truncating.
|
7.3.0 | bcpow() 関数は、指定されたスケールで値を返すようになりました。 これより前のバージョンでは、後に続く0の桁が省略された数値が返される可能性がありました。 |
例1 bcpow() の例
<?php
echo bcpow('4.2', '3', 2); // 74.08
?>
注意:
PHP 7.3.0 より前のバージョンでは、 bcmul() は
scale
引数で指定したものより少ない桁数を返す可能性がありました。 これはscale
で許された精度が不要な場合にだけ起きていました。 たとえば、以下のような場合です:例2 bcpow() で scale を指定する例
<?php
echo bcpow('5', '2', 2); // 結果は "25.00" ではなく "25" となります
?>