Questions tagged [gmpy]

GMPY and GMPY2 are C-coded Python extension modules that support fast multiple-precision arithmetic. GMPY only supports the GMP library and provides fast multiple-precision integer and rational arithmetic. GMPY2 adds support for fast, correctly rounded multiple-precision real and complex arithmetic.

About

GMPY is a legacy Python module that provides access to the GNU Multiple Precision (GMP) libary. GMP provides very fast and highly optimized routines for working with arbitrary precision integers (MPZ), rationals (MPQ), and (very limited) floating point numbers (MPF).

GMPY2 is the actively maintained replacement for GMPY. The limited floating point support from the GMP library has been replaced with correctly-rounded real arithmetic from the MPFR library. Correctly-rounded complex arithmetic from the MPC library is also available.

Links

73 questions
0
votes
1 answer

Does PyPy support gmpy2?

It seems from the discussions issue #60 and issue #40 that PyPy couldn't build gmpy before. All I intend to use currently is the probable prime is_prime code which is conveniently in gmpy2. I get the impression that the more calls to gmpy2 means…
qwr
  • 9,525
  • 5
  • 58
  • 102
0
votes
1 answer

gmpy2 log2 not accurate after 16 digits

When using log2() in gmpy2 it does not seem to be accurate after 16 digits. It seems to work fine at 15 digits but after that the answer is not correct using mpz(mpfr(2) ** mpfr(x)). Do I need change the precision? I thought python by itself would…
0
votes
1 answer

gmpy2 mpz type in a different base

I am trying to use MPZ to change the base of a number, but when I try mpz(16[, base=16]) I get an invalid syntax error. If I use mpz(0x16), it returns a base 10 number (22). Is it possible to store an MPZ type in a different base?
0
votes
1 answer

How to keep precision of gmpy2 mpfr in Numpy matrix operation

I am using Multiple-precision Rationals(mpfr) object in Numpy matrix, matrix([[ mpfr('-366998.93593422093364191959435957721088073331222596080623233278164906447646654043966366647797',300), …
PytLab
  • 539
  • 6
  • 12
0
votes
2 answers

Do I loose precision when converting from MPZ to long?

I wrote the following modulo exponentiation. But I am not sure if I will loose precision when converting from MPZ type to long. def mypowmod(base, power, modulus): base = gmpy.mpz(base) power = gmpy.mpz(power) modulus =…
drdot
  • 3,215
  • 9
  • 46
  • 81
0
votes
2 answers

python gmpy install error using MS Visual C++ Compiler Package for Python 2.7

i am trying to install gmpy via pip install gmpy in a test environment that was created using virtualenv but it is kicking back an error my laptop is a windows 8.1 x64 using Python 27 x32 i installed the Microsoft Visual C++ Compiler Package for…
jes516
  • 542
  • 1
  • 13
  • 30
0
votes
1 answer

Break python long into limbs

I'm trying to write an implementation of Montgomery multiplication in Python and I need an equivalent to GMP's mpz_getlimbn() for Python longs but I can't for the life of me seem to find one. Any help would be greatly appreciated. Edit I've…
Prydie
  • 1,807
  • 1
  • 20
  • 30
0
votes
1 answer

Sympy/mpmath/gmpy error while using multiprocessing

EDIT: This is a sympy bug. I have moved the discussion to https://github.com/sympy/sympy/issues/7457 I have a Python program that uses sympy to perform some core functionality that involves taking the intersection of a line and a shape. This…
Chinmay Kanchi
  • 62,729
  • 22
  • 87
  • 114
0
votes
2 answers

Looking for a divm or gmpy equivalent for Ruby

In the gmpy2 extension module for Python there's a multiple-precision integer type called mpz. It contains a powmod(x, y, m) function and I've been missing that one in Ruby. I was recently made aware that Ruby actually has a powmod. It's hidden in…
Jonas Elfström
  • 30,834
  • 6
  • 70
  • 106
0
votes
3 answers

pip installation of gmpy2

When I used pip to install gmpy2, I always got the version 1.16, i.e. gmpy instead of gmpy2. $ pip search gmpy gmpy - GMP or MPIR interface to Python 2.4+ and 3.x INSTALLED: 1.16 (latest) Is there any way to directly install…
user1096734
-1
votes
2 answers

Prime number generator using gmpy2 producing error

I'm trying to test a function in Jupyter Notebooks that uses gmpy2 to produce prime numbers but I'm getting the following output. import gmpy2 def solution(i): n = 2 while True: yield n n = str(gmpy2.next_prime(n)) for i in…
Nasrat Takoor
  • 344
  • 3
  • 8
-1
votes
3 answers

How to calculate Python float-number-th root of float number

I found the following answer here on Stackoverflow: https://stackoverflow.com/a/356187/1829329 But it only works for integers as n in nth root: import gmpy2 as gmpy result = gmpy.root((1/0.213), 31.5).real print('result:', result) results…
Zelphir Kaltstahl
  • 5,722
  • 10
  • 57
  • 86
-2
votes
1 answer

How is gmpy2.set_cache method correctly configured?

I am working on a python script that basically uses very long mpz integers (from gmpy2 library) and some small lists. Apart from other typical "pythonic" code optimizations, I have tried to reduce the times required for the calculations inside the…
iadvd
  • 179
  • 1
  • 2
  • 12
1 2 3 4
5