PHP4.04 增加了對無限精度運算的支援_PHP教程

來源:互聯網
上載者:User
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.
通過 GUN MP 庫,這些函數允許你使用任意長度的整數。你需要編譯 php 時使用 --with-gmp 參數

You can download the GMP library from http://www.swox.com/gmp/. This site also has the GMP manual available.
你可以從 http://www.swox.com/gmp/ 下載 GMP 庫,同時有手冊。

You will need GMP version 2 or better to use these functions. Some functions may require more recent version of the GMP library.
你需要 GMP 2.0 或更好的來使用這些函數。某些函數可能需要最新的 GMP庫

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 would 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.
注意:大多數 GMP 函數接受下面資源定義的 GMP 數值參數,當然,大多數函數也接受數字和字串參數,但是會被轉化為數字。同時,如果存在更快的函數來操作整形參數,則會使用那個更快的函數來操作整數。這是當然的,所以你可以在需要 GMP 數位地方用整數參數。

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.


http://www.bkjia.com/PHPjc/532488.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532488.htmlTechArticleThese 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 usin...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.