This article mainly introduces the method for retrieving the remainder of a large number (floating point number) in PHP, and analyzes the related operation skills related to php mathematical operations in the form of examples, for more information about how to use PHP to retrieve the remainder of a large number (floating point number), I analyzed the php mathematical operation skills in the form of examples. For more information, see
This example describes how to implement the remainder of a large number (floating point number) in PHP. We will share this with you for your reference. The details are as follows:
Generally, the first thing we think of when performing the remainder operation is to use the percent sign %. However, when the divisor is a large value beyond the int range, the remainder is inaccurate.
The remainder function of the php large number (floating point number) is as follows:
/*** Php return the remainder of a large number ** @ param int or float $ bn division * @ param int $ sn division * @ return int remainder * // Large number (floating point number) remainder method function Kmod ($ bn, $ sn) {return intval (fmod (floatval ($ bn), $ sn ));}
Test code:
// Function Kmod ($ bn, $ sn) {return intval (fmod (floatval ($ bn), $ sn ));} // 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 )); // add 1 $ bn = PHP_INT_MAX + 1 to the largest int integer; var_dump ($ bn); var_dump (Kmod ($ bn, $ sn )); var_dump (mod ($ bn, $ sn ));
Execution result:
int 2147483647int 1int 1float 2147483648int 2int -2
For more articles about how to implement the remainder of a large number (floating point number) in PHP, refer to the PHP Chinese network!