PHP4.04 added support for infinite precision operations

Source: Internet
Author: User
Tags gmp
Thesefunctionsallowyoutoworkwitharbitrary-lengthintegersusingtheGNUMPlibrary.Inordertohavethesefunctionsavailable, youmustcompilePHPwithGMPsupportbyusingthe -- wit These functions allow you to work with arbitrary-length integers using the gnu mp library. in order to have 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. Use the -- with-gmp parameter when compiling php

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 the http://www.swox.com/gmp/ and have a manual at the same time.

You will 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 need the latest GMP Library

These functions have been added in PHP 4.0.4.

Note: Most GMP functions accept GMP number arguments, defined as resource below. however, most of these functions will also accept numeric and string arguments, given that it is possible to convert the latter to a number. also, if there is a faster function that can operate on integer arguments, it wocould be used instead of the slower function when the supplied arguments are integers. this is done transparently, so the bottom line is that you can use integers in every function that expects GMP number. see also the gmp_init () function.
Note: Most GMP functions accept the GMP numerical parameters defined by the following resources. of course, most functions also accept numbers and string parameters, but are converted to numbers. At the same time, if a faster function is used to operate integer parameters, the faster function is used to operate 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 will calculate factiorial of 1000 (pretty big number) very fast.


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.