Comments (7)
Is checking for an environment variable GMPY_NO_DECIMAL (or similar) an
acceptable
solution?
(I wonder if importing the decimal module is a valid approach if decimal is
rewritten
in C?)
Original comment by casevh
on 4 May 2009 at 6:02
- Added labels: Type-Enhancement
- Removed labels: Type-Defect
from gmpy.
Why is the code needed in the first place?
If I recall correctly, Decimal used to raise TypeError on unknown types but
this has
been fixed to return NotImplemented in recent Python versions. It should be
possible
to do everything in gmpy's coercion code, without monkeypatching decimal.py.
Original comment by [email protected]
on 4 May 2009 at 6:11
from gmpy.
Good point. I'll see what happens when I remove it.
Original comment by casevh
on 4 May 2009 at 6:25
from gmpy.
In the current trunk versions, I've removed the automatic import of Decimal. In
combination with the changes required for Python 3.x support, I ended up
removing
support for coerce since it isn't supported with Python 3.x. This led to various
subtle changes with number conversions. I tried to mimic Python's behavior as
much as
possible. In gmpy 1.04, mpz(1) + 1.2 returns mpz(2). I think the implicit
conversion
of 1.2 to 1 is incorrect. With the new logic in trunk, this will generate a
TypeError. The alternative would be to return an mpf, but then I'd need to
guess the
desired precision. I think conversions that can discard information should not
be
done automatically.
Do you have any preferences?
Original comment by casevh
on 8 Jun 2009 at 7:21
from gmpy.
I get a float:
>>> import gmpy
>>> gmpy.mpz(2) + 1.2
3.2000000000000002
I think there is some code that relies on this.
Original comment by [email protected]
on 8 Jun 2009 at 9:41
from gmpy.
You're correct. I got confused with all the revisions I've been testing. The
current
behavior has quirks such as:
>>> gmpy.version()
'1.04'
>>> gmpy.mpz(10) == 10.0
False
>>> gmpy.mpz(10**400) + 1.2
inf
>>> gmpy.mpz(10) + decimal.Decimal('10.2')
mpz(20)
I probably got confused with the current state of Decimal conversion. How
important
is consistency between Decimal and float? I think the most consistent behavior
would
be either raise an error and force explicit conversion, or convert to mpf and
guess
at the precision. All this really does is consistently break both scenarios,
though. ;-)
Original comment by casevh
on 8 Jun 2009 at 11:57
from gmpy.
The automatic import and monkey-patching of Decimal has been removed in gmpy
1.10.
Original comment by casevh
on 5 Jul 2009 at 5:13
- Changed state: Fixed
from gmpy.
Related Issues (20)
- Adding _sympy_ method to mpfr type for robust interoperability with sympy HOT 3
- Expose mpz_probab_prime_p() int return values from is_prime() HOT 5
- Missing methods on mpz c.f. int HOT 11
- "latest" documentation looks outdated HOT 7
- Documentation has invalid function signatures
- Fix vectorcall support on Python 3.7 HOT 1
- Use pytest for testing? HOT 6
- Incorrect interpretation of numbers with high bases HOT 3
- Incompatible (with int) parsing of the sign in the mpz constructor HOT 3
- pycharm inspection "Unexpected argument" for gmpy2.mpz(...) HOT 9
- gmpy2.xmpz bit reverse padding HOT 1
- Efficient fixed-base modular exponentiation with powmod_exp_list?
- Compiler warnings on Windows 2022 & msys2 HOT 3
- Argument order yn() and jn() inconsistent with MPFR and mpmath HOT 3
- 2 tests fail HOT 4
- Pickling is slow wrt int's HOT 2
- Breaking changes in Python 3.12.0a7 release HOT 4
- Add function csqrt HOT 2
- Incompatible (wrt the MPC library) parsing in the master HOT 1
- bit_count() not found HOT 3
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.