Omar Khalid
Omar Khalid

Reputation: 81

php power of number mod number not work

why this function return 0 ?

public function encrypt(){
    return (pow(123,17)%3233);
}

Upvotes: 2

Views: 132

Answers (1)

Rizier123
Rizier123

Reputation: 59691

What happens here is you get an integer overflow. Your number is way bigger than PHP_INT_MAX. So to still be able to do this calculation you can use the BC math library .

So just use bcpowmod(), e.g.

echo bcpowmod(123, 17, 3233);

Upvotes: 2

Related Questions