Closed GoogleCodeExporter closed 9 years ago
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
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 fredrik....@gmail.com
on 4 May 2009 at 6:11
Good point. I'll see what happens when I remove it.
Original comment by casevh
on 4 May 2009 at 6:25
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
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 fredrik....@gmail.com
on 8 Jun 2009 at 9:41
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
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
Original issue reported on code.google.com by
fredrik....@gmail.com
on 3 May 2009 at 10:13