andyvand / gmpy

Automatically exported from code.google.com/p/gmpy
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Changing number conversion logic. #30

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
gmpy 1.04 (and possibly 1.05) use the functions anynum2mpz, anynum2mpq, and
anynum2mpf to convert to convert arguments to the desired type. This can
generate results such as "mpz(1) + 1.2" returning 2. I'd like to change the
logic as follows:

anyint2mpz replaces anynum2mpz and only converts integer objects to an mpz.
Currently only recognizes int, long, and valid strings.

anyrational2mpq replaces anynum2mpq and converts integer and rational
objects to an mpq. Currently only recognizes int, long, and valid strings.
I will add support for Python 3.x Fraction type.

anyreal2mpf replaces anynum2mpf and converts all number types to an mpf. It
does recognize the Decimal type and I will add support for Fraction.

This will change some exceptions from ValueError to TypeError and break
some mixed-type expressions.

With this logic, mpz + float will generate a TypeError. The alternative
would be to have mpz + float return an mpf. I would rather make such
conversion explicit.

Opinions?

Original issue reported on code.google.com by casevh on 8 Jun 2009 at 7:09

GoogleCodeExporter commented 9 years ago
I've adopted the convention that the result types will match the Python 3.x 
behavior
but with added rule that the result type will always be a gmpy type. Hence, mpz 
+
float will return an mpf.

Original comment by casevh on 5 Jul 2009 at 5:27