Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string representation of mpq wihich are integers #41

Closed
GoogleCodeExporter opened this issue Mar 15, 2015 · 9 comments
Closed

string representation of mpq wihich are integers #41

GoogleCodeExporter opened this issue Mar 15, 2015 · 9 comments

Comments

@GoogleCodeExporter
Copy link

In gmpy 1.11

>>> print mpq(3,1)
3/1

while in gmpy 1.0.3
>>> print mpq(3,1)
3

Why has this been changed? The latter is shorter and behaves as Fraction
>>> from fractions import Fraction
>>> print Fraction(3,1)
3

and as in Sage
sage: R.<x> = QQ[]
sage: 3*x + 2/3
3*x + 2/3
(not 3/1*x + 2/3)

I would like to suggest to go back to this form, or at least to allow
it setting an environment parameter.

Mario

Original issue reported on code.google.com by mario.pe...@gmail.com on 21 Jul 2010 at 8:28

@GoogleCodeExporter
Copy link
Author

Mario,

The change was an error on my part. mpq is supposed to behave just like 
Fraction. I'll create tags/gmpy_1_13 with the fix in a day or two.

Thanks for the bug report.

Case

Original comment by casevh on 22 Jul 2010 at 6:03

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Thanks.

> mpq is supposed to behave just like Fraction.

Another difference between the two is
>>> a = mpq(1,3)
>>> print a.numer()
1

>>> b = Fraction(1,3)
>>> print b.numerator
1

similarly for the denominator.
Is it possible to add to gmpy.mpq something like

numerator = property(numer)

to allow the same call for both?

Mario

Original comment by mario.pe...@gmail.com on 22 Jul 2010 at 7:44

@GoogleCodeExporter
Copy link
Author

I've committed tags/gmpy_1_13 and it should fix the formatting. I also added 
improved caching for mpq types. I'm curious if you notice any performance 
improvements.

I'll work on adding .numerator etc. next.

Case

Original comment by casevh on 23 Jul 2010 at 6:40

@GoogleCodeExporter
Copy link
Author

Thank you.

With version 1.13 I get 1-3% speedup.

Mario

Original comment by mario.pe...@gmail.com on 24 Jul 2010 at 6:57

@GoogleCodeExporter
Copy link
Author

I've added .numerator and .denominator to 1.13.

How soon do need this version officially released?

Case

Original comment by casevh on 26 Jul 2010 at 6:47

@GoogleCodeExporter
Copy link
Author


> I've added .numerator and .denominator to 1.13.

Great!

Mario

Original comment by mario.pe...@gmail.com on 26 Jul 2010 at 2:45

@GoogleCodeExporter
Copy link
Author

1.13 is officially released.

Original comment by casevh on 31 Aug 2010 at 5:23

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Mario,

While running some additional tests, I think my fix has a problem. Below is the 
behaviour of the Fractions module, gmpy, and gmpy2 (development branch).

>>> from fractions import Fraction
>>> str(Fraction(3,1))
'3'
>>> repr(Fraction(3,1))
'Fraction(3, 1)'
>>> from gmpy import mpq
>>> str(mpq(3,1))
'3'
>>> repr(mpq(3,1))
'mpq(3)'
>>> from gmpy2 import mpq
>>> str(mpq(3,1))
'3'
>>> repr(mpq(3,1))
'mpq(3,1)

Right now, gmpy 1.13 doesn't display the denominator of 1 even with repr. (The 
earlier bug displayed a denominator of 1 in all cases.) I'm planning a 1.14 
release within a few weeks. Will you have any problems if I use the gmpy2 
formatting rules since they match Fraction's?

casevh

Original comment by casevh on 26 Oct 2010 at 6:09

@GoogleCodeExporter
Copy link
Author

Hi,

str(mpq(3,1))

 is quite fine.

Mario

Original comment by mario.pe...@gmail.com on 26 Oct 2010 at 8:37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant