gmpy/decimal interoperation

Nick Craig-Wood nick at craig-wood.com
Mon Nov 14 10:30:07 CET 2005


Alex Martelli <aleax at mail.comcast.net> wrote:
>  As things stand now (gmpy 1.01), an instance d of decimal.Decimal cannot
>  transparently become an instance of any of gmpy.{mpz, mpq, mpf}, nor
>  vice versa (the conversions are all possible, but a bit laborious, e.g.
>  by explicitly going through string-forms).
> 
>  I'm thinking about possible ways to fix this, in whole or in part, but,
>  before I spend more time on this, I was wondering if there's anybody
>  else who'd be interested

I can't ever imaging mixing the two.  I use GMPY when I want fast
inifinite precision artithmetic.  I'd use decimal if I wanted to do
decimal arithmetic on currency or something like that (or perhaps if I
hadn't discovered GMPY in which case I wouldn't be mixing with GMPY!)

> if so, maybe we can discuss which conversions should happen
> implicitly

None I'd say!  Perhaps make a less laborious manual conversion
function, but I don't think implicit conversion is that useful since
decimal and gmpy are solving quite different problems.

Implicit conversions also opens the can of worms - what is the
preferred promotion type? decimal + mpf == decimal? mpf? mpq?

IMHO of course!
-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list