Git Product home page Git Product logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 6, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 6, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 6, 2024
Good point. I'll see what happens when I remove it.

Original comment by casevh on 4 May 2009 at 6:25

from gmpy.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 6, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 6, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 6, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 6, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.