PHP implements the remainder of a large number (floating point number ).

Source: Internet
Author: User

PHP implements the remainder of a large number (floating point number ).

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 1 float 2147483648int 2int-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.