-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError in gmpy2.iroot #257
Comments
The exception should really have been ValueError. By default, gmpy2 just mimics the behavior of the underlying GMP functions. The GMP functions expect the root to be pass as an unsigned long int. (Note: this could be different of 32 bit platforms or Windows.) With the size constraints of the mpz type, the result of iroot() will always be mpz(1) for any root large enough to trigger the overflow. If you think it is helpful, I can change iroot() to always return mpz(1) instead of raising an exception. |
Now:
@casevh, probably you can close this issue. |
Do gmpy operations generally overflow? I would rather have an error than an overflow. |
@asmeurer, CPython operations on int's overflow...
|
That's not an overflow, that's an error. |
I believe it should raise an OverflowError. GMP's mpz_root function requires and "unsigned long" argument. CPython raises an OverflowError exception when an argument can't be converted to a native C type. I was using my conversion code that returned ValueError but I'm now using Python's conversion code. Are you ok with raising OverflowError? |
OverflowError seems like the correct exception type to use. |
Unless the first operand is really large ( |
@isuruf You are correct. I'll leave it alone and close the ticket. I'll verify the Windows semantics, too. |
However:
And on 32 bit:
|
I have a patch that returns |
An
In principle Would it make sense to export |
If |
What should we do on 64-bit Windows? GMP defines mpbitcnt_t as an unsigned long. MPIR defines mpbitcnt_t as an unsigned long long. I have a patch for GMP that changes the definition of mpbintcnt_t to unsigned long long. I used to statically link gmpy2 so I didn't mind using the patched version of gmpy2. gmpy2 now exports a C-API that is used by Cython so I've started to provide DLLs for GMP, MPFR, and MPC. (See issue #320.) Should I distribute DLLs and header files that strictly follow GMP's definition or use the patched version? I personally prefer the patched version of GMP since it makes 64-bit Windows, Linux, and MacOS behave the same. |
gmpy2
produces correct result upton=2**63-1
but withn=2**63
it leads toTypeError
Related to the sympy issue.
Converting the arguments to
mpz
also doesn't work as:The text was updated successfully, but these errors were encountered: