(PHP 4, PHP 5, PHP 7, PHP 8)
bcmod — 2 つの任意精度数値の剰余を取得する
num1
の、
num2
を法とする剰余を取得します。
結果は num1
と同じ符号を持ちます。
num1
左オペランドを表す文字列。
num2
右オペランドを表す文字列。
scale
null
, it will default to the default scale set with bcscale(),
or fallback to the value of the
bcmath.scale
INI directive.
剰余を文字列で返します。
num2
が 0 の場合は null
を返します。
This function throws a ValueError in the following cases:
num1
or num2
is not a well-formed BCMath numeric string.
scale
is outside the valid range.
This function throws a DivisionByZeroError
exception if num2
is 0
.
バージョン | 説明 |
---|---|
8.0.0 |
scale は nullable になりました。
|
8.0.0 |
Dividing by 0 now throws a DivisionByZeroError exception instead of returning null.
|
7.2.0 |
num1 と num2 は
整数に切り詰められることがなくなりました。
よって、bcmod() の振る舞いは
% 演算子ではなく、
fmod() に従うことになります。
|
7.2.0 |
scale パラメータが追加されました。
|
例1 bcmod() の例
<?php
bcscale(0);
echo bcmod( '5', '3'); // 2
echo bcmod( '5', '-3'); // 2
echo bcmod('-5', '3'); // -2
echo bcmod('-5', '-3'); // -2
?>
例2 bcmod() に小数の値を指定する
<?php
bcscale(1);
echo bcmod('5.7', '1.3'); // 0.5 as of PHP 7.2.0; 0 previously
?>