PHP4.04 adds support for infinite precision operations _php tutorial

Source: Internet
Author: User
Tags gmp
These functions allow you to work with arbitrary-length integers using the GNU MP library. In order to has these functions available, you must compile PHP with GMP support by using the--WITH-GMP option.
Through the GUN MP library, these functions allow you to use integers of any length. You need to compile PHP using the--WITH-GMP parameter

You can download the GMP library from http://www.swox.com/gmp/. This site also has the GMP manual available.
You can download the GMP library from http://www.swox.com/gmp/and have a manual.

You'll need GMP version 2 or better to use these functions. Some functions may require more recent version of the GMP library.
You need GMP 2.0 or better to use these functions. Some functions may require the latest GMP library

These functions has been added in PHP 4.0.4.

Note:most GMP functions Accept GMP number arguments, defined as resource below. However, most of these functions would also accept numeric and string arguments, given that it's possible to convert the L Atter to a number. Also, if there is a faster function so can operate on integer arguments, it would be used instead of the slower function When the supplied arguments is integers. This is do transparently, so the bottom line is, which can use integers in every function that expects GMP number. See also the Gmp_init () function.
NOTE: Most GMP functions accept the GMP numeric parameters defined by the resources below, and of course, most functions accept both numeric and string parameters, but are converted to numbers. At the same time, if there is a faster function to manipulate the shaping parameters, then the faster function is used to manipulate the integers. This is of course, so you can use integer parameters where GMP numbers are needed.

Example 1. factorial function using GMP

function Fact ($x) {
if ($x <= 1)
return 1;
Else
Return Gmp_mul ($x, Fact ($x-1));
}

Print Gmp_strval (fact (1000)). "N";
?>

This would calculate factiorial of (pretty big number) very fast.


http://www.bkjia.com/PHPjc/532488.html www.bkjia.com true http://www.bkjia.com/PHPjc/532488.html techarticle These functions allow you to work with arbitrary-length integers using the GNU MP library. In order to has these functions available, you must compile PHP with GMP support by usin ...

  • 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.