aleaxit / gmpy

General Multi-Precision arithmetic for Python 2.6+/3+ (GMP, MPIR, MPFR, MPC)
https://gmpy2.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
522 stars 86 forks source link

Support negative exponents in mul_2exp #458

Closed skirpichev closed 12 months ago

skirpichev commented 1 year ago
codecov-commenter commented 1 year ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (e34324a) 85.05% compared to head (eee6f31) 85.35%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #458 +/- ## ========================================== + Coverage 85.05% 85.35% +0.29% ========================================== Files 49 49 Lines 11733 11714 -19 Branches 2204 2204 ========================================== + Hits 9980 9998 +18 + Misses 1753 1716 -37 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

skirpichev commented 1 year ago

This does make sense for div_2exp() as well. But I'm thinking about some code reorganization first.

Maybe it does make sense to add some GMPy_Integer_As??? utility function, that try conversion to unsigned long and then to long?

casevh commented 1 year ago

This does make sense for div_2exp() as well. But I'm thinking about some code reorganization first.

Maybe it does make sense to add some GMPy_Integer_As??? utility function, that try conversion to unsigned long and then to long?

That would make sense. We need to include 64-bit values on Windows where long is only 32-bits. size_t and ssize_t could be used as the types.

skirpichev commented 1 year ago

That would make sense.

Is there any potential use cases besides div_2exp()?

casevh commented 1 year ago

Is there any potential use cases besides div_2exp()?

Those would be the most common. Almost any code that relies on bit positions or bit length could use size_t or ssize_t. See the bit indexing code in gmpy2_xmpz_misc.c for use of ssize_t.

skirpichev commented 12 months ago

@casevh, I think this is ready for review.

size_t and ssize_t could be used as the types.

I came to GMPy_Integer_AsUnsignedLongOrLong() helper function. GMP only has *_si/ui functions to work with signed/unsigned long.

skirpichev commented 12 months ago

CI failures are unrelated to this pr.

casevh commented 12 months ago

I came to GMPy_Integer_AsUnsignedLongOrLong() helper function. GMP only has *_si/ui functions to work with signed/unsigned long.

Agreed. Looks good. I'll merge it this weekend / when you tell me it is ready.

skirpichev commented 12 months ago

@casevh, it was mentioned above, that this pr is ready for review.

skirpichev commented 12 months ago

@casevh, I've added yet another (last, I think ;)) commit to this PR, which utilizes new function in iroot() (to raise OverflowError instead of ValueError's on overflow).

casevh commented 12 months ago

Thanks.