Computer >> Computer tutorials >  >> Programming >> PHP

gmp_invert() function in PHP


The gmp_invert() function gets the modular inverse of a GMP number in other number.

Example

Let’s say we have two numbers 5 and 14, therefore 3 is the modulo inverse of 5:

(3*5) mod 14 = 1

The above output is:

3

Syntax

gmp_invert ( num1, num2 )

Parameters

  • num1: The first GMP number.

  • num1: The second GMP number.

Return

The gmp_invert() function returns the inverse modulo of two numbers passed.

Example

The following is an example:

<?php
   $n1 = "5";
   $n2 = "14";
   $res = gmp_invert($n1, $n2);
   echo $res;
?>

Output

The following is the output:

3