This article mainly introduces PHP implementation of large number (floating point) to take the remainder of the method, combined with examples of the PHP mathematical operations related operation skills, the need for friends can refer to the next
In this paper, we describe the method of implementing large number (floating point) redundancy in PHP. Share to everyone for your reference, as follows:
Generally we take the remainder of the operation of the first thought is to use percent%, but when the divisor is a very large value, beyond the int range, so that the surplus is not accurate.
PHP large number (floating point) Take the remainder function:
/** * PHP Large number of remainder * * @param int or float $bn divisor * @param int $SN dividend * @return int remainder *///large number (floating point) method function Kmod ($bn, $SN) { return intval (Fmod (Floatval ($bn), $SN));}
Test code:
Large number (floating point) method function Kmod ($bn, $SN) { return intval (Fmod (Floatval ($bn), $SN));} Integer take redundancy method function mod ($bn, $SN) { return $bn% $sn;} The largest int integer $bn = php_int_max, $sn = 11;var_dump ($bn), Var_dump (Kmod ($bn, $SN)), Var_dump (mod ($bn, $SN)), or//to the largest int integer plus 1$bn = Php_int_max + 1;var_dump ($bn), Var_dump (Kmod ($bn, $SN)), Var_dump (mod ($bn, $SN));
Execution Result:
int 2147483647int 1int 1float 2147483648int 2int-2