HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

bcpowmod

Description

The bcpowmod of BCMath for PHP raises an arbitrary precision number to another, reduced by a specified modulus.

Syntax

bcpowmod(
    string $num,
    string $exponent,
    string $modulus,
    ?int $scale = null
): string

Parameters

num

The base, as an integral string (i.e. the scale has to be zero).

exponent

The exponent, as an non-negative, integral string (i.e. the scale has to be zero).

modulus

The modulus, as an integral string (i.e. the scale has to be zero).

scale

Sets the number of digits after the decimal place in the result.

If omitted, it will default to the scale set globally with the bcscale() function, or fallback to 0 if this has not been set.

Return

Returns the result as a string, or false if modulus is 0 or exponent is negative.

Examples

1 · num exponent modulus

<?

$num = "2";
$exponent = "3";
$modulus = "5";

$return = bcpowmod($num, $exponent, $modulus);

var_dump($return);
string(1) "3"

2 · scale

<?

$num = "2";
$exponent = "3";
$modulus = "5";
$scale = 6;

$return = bcpowmod($num, $exponent, $modulus, $scale);

var_dump($return);
string(8) "3.000000"

3 · bcscale

<?

$scale = 6;

bcscale($scale);

$num = "2";
$exponent = "3";
$modulus = "5";

$return = bcpowmod($num, $exponent, $modulus);

var_dump($return);
string(8) "3.000000"