Comments (3)
As a workaround I'm using bit_mask and bit shift:
from gmpy2 import mpz, bit_mask
# one bit
(a >> 4) & 1
# multi bit
(a >> 4) & bit_mask(3)
from gmpy.
This is an interesting issue. I need to think about the best solution.
Let's assume a is always a negative 'mpz'.
What should a[2:] return? Without a given stop value, this will effectively lock up a system, and eventually crash the interpreter, while it tries to return an infinite number. I think maintaining the existing behavior is best when no stop value is given.
If we assume that a stop value is present, the change looks easy on Python 3.6.1 and later. (New C-API functions introduced.) I need to see if there is a reasonable fix for older versions of Python.
from gmpy.
That's interesting, I hadn't thought about the unbounded slices! I wonder if unbounded slices are really necessary though? As a user it seems a bit counter-intuitive to me that a[0:]
and a
are not the same
In [21]: a = xmpz(-2)
In [22]: a[0:]
Out[22]: mpz(2)
Maybe unbounded slices in getter expressions should be forbidden for consistency? A user can use bit_length() to be explicit if this is really what they want.
But i do see why unbounded slices could be useful on the LHS, looks like I found another edge case though, I'll open a second issue :)
Edit: and here's the issue report #342
from gmpy.
Related Issues (20)
- complex conjugate crash HOT 2
- Linux wheels in the latest release (2.2.0a1) are broken HOT 10
- What is the paper that `is_extra_strong_lucas_prp` is referring to? HOT 4
- About the case where `k=0` is input to `lucasu_mod` and `lucasv_mod` HOT 2
- gmpy-2.1.5 fails to compile with python-3.12 HOT 11
- cython C-API is broken in published wheels (and in the build_wheels.yml CI workflow) HOT 9
- Pip install build fails, can't find mpc.h HOT 6
- Deprecate local_context()? HOT 18
- Impending release of gmpy2 2.2.0a2 HOT 10
- Issue with large factorial HOT 6
- Access to gmplib.org
- Alternatives to using private API for conversion to/from CPython int's HOT 1
- Build & tests wheels for M$ Windows
- Executing advanced arithmetic operations --C++ to gmpy2 in Python HOT 1
- Is there an alternative for Decimal? HOT 5
- Please make a non-preview release with Python 3.12 support — thank you! HOT 18
- gmpy2 2.2.0a2 missing on PyPI HOT 6
- Windows build comments HOT 2
- Major issue in Linux wheels HOT 1
- Dead paper link in comments
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmpy.