I have to calculate a % b for two very large numbers.
I can not use the default modulo operator, because a and b are larger then PHP_INT_MAX, so I have to handle them as “strings”.
I know that there exists special math libraries like BC or GMP but I can’t use them, because my app probably will hosted on a shared host, where these are not enabled.
I have to write a function in php that will do the job. The function will take two strings (the two number) as parameters and have to return a % b, but I don’t know how to start?
How to solve this problem?
Since PHP 4.0.4, libbcmath is bundled with PHP. You don’t need any external libraries for this extension. These functions are only available if PHP was configured with –enable-bcmath .
The Windows version of PHP has built-in support for this extension. You do not need to load any additional extensions in order to use these functions. You should be able to enable these functions yourself, without any action on the part of the hosting company.