gmpy2安裝使用方法

來源:互聯網
上載者:User

標籤:

GMP(GNU Multiple Precision Arithmetic Library,即GNU高精度算術運算庫),它是一個開源的高精度運算庫,其中不但有普通的整數、實數、浮點數的高精度運算,還有隨機數產生,尤其是提供了非常完備的數論中的運算介面,比如Miller-Rabin素數測試演算法、大素數產生、歐幾裡德演算法、求域中元素的逆、Jacobi符號、legendre符號等。
gmpy2是Python的一個擴充庫,是對GMP的封裝,它的前身是gmpy,經過其作者的調整和封裝,使得gmpy2的使用大大簡化。

-------

1、windows上安裝gmpy2

在windows上直接安裝wheel檔案就方便多了。

https://pypi.python.org/pypi/gmpy2

這裡面有python2.6、2.7、3.2、3.3、3.4版本的wheel檔案,下載後用pip安裝即可。(暫時還找不到3.5版本)

 

2、linux上安裝gmpy2

gmpy2是依賴GMP、MPFR、MPC三個庫,故此在linux上安裝前得先安裝這3個庫。

為了後續安裝的方便,先建立2個檔案夾。

mkdir -p $HOME/srcmkdir -p $HOME/static

 

3、安裝GMP

GMP(The GNU Multiple Precision Arithmetic Library) is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers.
https://gmplib.org/

當前最新的是6.1.1

cd $HOME/srcwget https://gmplib.org/download/gmp/gmp-6.1.1.tar.bz2tar -jxvf gmp-6.1.1.tar.bz2cd gmp-6.1.1./configure --prefix=$HOME/static --enable-static --disable-shared --with-picmake && make check && make install

 

4、安裝MPFR

The MPFR library is a C library for multiple-precision floating-point computations with correct rounding.
http://www.mpfr.org/mpfr-current/#download
當前最新的是3.1.4

cd $HOME/srcwget http://www.mpfr.org/mpfr-current/mpfr-3.1.4.tar.bz2tar -jxvf mpfr-3.1.4.tar.bz2cd mpfr-3.1.4./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/staticmake && make check && make install

 

5、安裝MPC

GNU MPC is a C library for the arithmetic of complex numbers with arbitrarily high precision and correct rounding of the result.
http://www.multiprecision.org/index.php?prog=mpc&page=download
當前最新的是1.0.3

cd $HOME/srcwget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gztar -zxvf mpc-1.0.3.tar.gzcd mpc-1.0.3./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static --with-mpfr=$HOME/staticmake && make check && make install

 

6、安裝gmpy2

cd $HOME/srcgit clone https://github.com/aleaxit/gmpycd gmpypython setup.py build_ext --static=$HOME/static install

安裝後,命令列進入python模式後,輸入import gmpy2沒報錯就成功了。

 

7、gmpy2使用方法

這裡pcat就介紹找一百以內的素數,更多gmpy2的用法自己搜尋吧,或者以後補充(←_←)。

import gmpy2for i in xrange(100+1):    if gmpy2.is_prime(i):        print i

 

gmpy2安裝使用方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.