Comments (4)
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.
Closing.
Original comment by casevh
on 9 Mar 2011 at 10:42
- Changed state: Done
from gmpy.
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.
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)
- 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
- Build failure on CPython 3.13 (dev)
- test failures with mpfr 4.2.1 (change in MPFR formatted functions) HOT 31
- New version? 🤔 HOT 15
- 2.1.5: test suite fails with errors `invalid option: '+SKIP_MPC_LESS_THAN_110'` HOT 9
- 2.1.5: *.h and *.pxd files are installed HOT 5
- Is the `is_strong_bpsw_prp` code correct? HOT 2
- Assessment of the difficulty in porting CPU architecture for the gmpy
- Description of `is_euler_prp` HOT 1
- mpz object missing to_bytes() method HOT 4
- complex conjugate crash HOT 2
- Linux wheels in the latest release (2.2.0a1) are broken HOT 10
- What is the paper that `is_extra_strong_lucas_prp` is referring to? HOT 4
- About the case where `k=0` is input to `lucasu_mod` and `lucasv_mod` HOT 2
- gmpy-2.1.5 fails to compile with python-3.12 HOT 11
- cython C-API is broken in published wheels (and in the build_wheels.yml CI workflow) HOT 9
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.