Giter Club home page Giter Club logo

Comments (4)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 29, 2024
Hi Chris,

Your particular use case didn't make into changes.txt. Sorry about that!

I tried to mimic the behavior of the Fraction type introduced in Python 2.6. I 
use  the latest version of Python as a reference so the following examples use 
3.2. (Fraction in Python 2.6 won't directly convert a float to a Fraction; you 
need to use the from_float() method.)

>>> fractions.Fraction(0.999)
Fraction(8998192055486251, 9007199254740992)
>>> fractions.Fraction(0.999) + 0.1
1.099
>>> fractions.Fraction('0.999')
Fraction(999, 1000)
>>> fractions.Fraction('0.999') + fractions.Fraction(0.1)
Fraction(4949455990480175129, 4503599627370496000)
>>> fractions.Fraction('0.999') + fractions.Fraction('0.1')
Fraction(1099, 1000)
>>> 

Several behaviors changed. First, Fraction plus float returns a float.

Second, conversion from a float to a rational are now exact in Fraction. gmpy 
used to return an user-friendly approximation when converting a float to an 
mpq. This change occurred in gmpy2.

>>> import gmpy,gmpy2
>>> gmpy.mpq(0.999)
mpq(999,1000)
>>> gmpy2.mpq(0.999)
mpq(8998192055486251,9007199254740992)
>>> 

Conversion from a string still works.

>>> gmpy.mpq('0.999')
mpq(999,1000)
>>> gmpy2.mpq('0.999')
mpq(999,1000)
>>> 

I'm also working towards support for better floating point numbers in gmpy2. 
The MPFR library provides correctly rounded base-2 arithmetic and I wanted to 
support exact float to mpfr conversions so it made sense to do exact float to 
mpq conversions.

After gmpy 1.11, I realized the changes I wanted to do where becoming more and 
more invasive, so I renamed the development branch to gmpy2.

I think 1.04 was the last version to support the old-style conversion rules but 
it doesn't support Python 3.x.

Case


Original comment by casevh on 25 Feb 2011 at 4:28

  • Changed state: Accepted
  • Added labels: Type-Other, Priority-Low
  • Removed labels: Type-Defect, Priority-Medium

from gmpy.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 29, 2024
Closing.

Original comment by casevh on 9 Mar 2011 at 10:42

  • Changed state: Done

from gmpy.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 29, 2024
Sorry, I forgot to comment to say thank you for the detailed reply. It's 
unfortunate from my point of view (as an author of software that depends on 
gmpy) that these behaviors changed in a minor release, although I understand 
why you made the changes.

Thanks for all the work on gmpy.

Chris 

P.S. Sorry if this re-opens the bug - that's not the point of this comment.

Original comment by [email protected] on 10 Mar 2011 at 8:51

from gmpy.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 29, 2024
Chris,
Is your software generally available? If so, and if it has a test suite that 
exercises a gmpy, I'd be willing to test newer releases against it. I currently 
test against mpmath and I'm looking for more real-world code to use for testing.

Case

Original comment by casevh on 11 Mar 2011 at 3:12

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.