PHP implementation of large number (floating point) to take the remainder of the method

Source: Internet
Author: User
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

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.