Closed GoogleCodeExporter closed 8 years ago
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
Closing.
Original comment by casevh
on 9 Mar 2011 at 10:42
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 ceb...@gmail.com
on 10 Mar 2011 at 8:51
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
Original issue reported on code.google.com by
ceb...@gmail.com
on 24 Feb 2011 at 3:14