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 -- if so, maybe we can discuss which
conversions should happen implicitly (e.g., if you try to sum a Decimal
and an mpz, maybe the latter should implicitly become a Decimal, just
like an int would, so that the result is a Decimal) and which ones
should only happen on explicit request (e.g., gmpy.mpf(d) should produce
an mpf instance, just as calling gmpy.mpf on an int instance would).
Alex 3 1868
Alex Martelli <al***@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 <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Alex Martelli 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 -- if so, maybe we can discuss which conversions should happen implicitly (e.g., if you try to sum a Decimal and an mpz, maybe the latter should implicitly become a Decimal, just like an int would, so that the result is a Decimal) and which ones should only happen on explicit request (e.g., gmpy.mpf(d) should produce an mpf instance, just as calling gmpy.mpf on an int instance would).
Alex
This is a bit off topic but I would like to know how you would go about
doing an implicit operation with an mpz and Decimal becoming a Decimal.
I would like to use something like this to make the float and complex
types more interoperable with mpq and cmpq in my clnum module
( http://calcrpnpy.sourceforge.net/clnumManual.html). In those cases, I
would like the mpq to degrade to float and the cmpq to degrade to
complex (right now they just raise exceptions). Seems like you need to
either modify the target type to recognize the new one or the code has
to get very complex to handle all the combinations.
Ray
Raymond L. Buvel <le******@wi.rr.com> wrote:
... This is a bit off topic but I would like to know how you would go about doing an implicit operation with an mpz and Decimal becoming a Decimal.
I would tweak Decimal.__new__ to accept an mpz and perform an int() on
it before proceeding as it does now, for example.
I would like to use something like this to make the float and complex types more interoperable with mpq and cmpq in my clnum module (http://calcrpnpy.sourceforge.net/clnumManual.html). In those cases, I would like the mpq to degrade to float and the cmpq to degrade to complex (right now they just raise exceptions). Seems like you need to either modify the target type to recognize the new one or the code has to get very complex to handle all the combinations.
Modifying the target type is indeed what I had in mind (for Decimal).
As long as the target-type is Python-coded, you can substitute its
__new__ with a wrapped version. Unfortunately, float and complex
aren't; but fortunately, Python does have for these cases appropriate
special methods/slot that your SOURCE type can implement. In gmpy, I
have float 'upgraded' to mpq (with a Stern-Brocot heuristic), but it
wouldn't be any harder to have the mpq 'degrade' to float instead.
Alex This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jean-Pierre Andreaux |
last post by:
Gmpy module was a wrapper of the GNU MP library. It seems that no
evolution is done on this module since 2001. Indeed, Gmpy is not
supported in Python 2.2 nor 2.3.
My question is the following:...
|
by: Mensanator |
last post by:
In the program that follows, I get the following warning message:
collatz_.py:37: RuntimeWarning: tp_compare didn't return -1, 0 or 1
while b>1:
In this case, b is a gmpy.mpz number. The...
|
by: Alex Martelli |
last post by:
Thanks to David Bolen, who did the build, I have been able to make
available a win32 packaging for gmpy 1.0 on python 2.4 alpha 2 (should
work on any later Python 2.4 as well, but I have no way to...
|
by: mensanator |
last post by:
Since the following discussion took place (unresolved),
...
|
by: Alex Martelli |
last post by:
I have fixed almost all of the outstanding bugreports and feature
request for gmpy: divm doesn't leak memory any more, truediv and
floordiv are implemented for all types, etc -- in the current CVS...
|
by: Alex Martelli |
last post by:
I've added to gmpy.sf.net two binary packages of gmpy for Mac OS X 10.4,
one for the Python 2.3.5 that comes with the system and one for Bob
Ippolito's build of 2.4.1. They still need GMP to be...
|
by: mensanator |
last post by:
## Holy Mother of Pearl!
##
## >>> for i in range(10):
## for j in range(10):
## print '%4d' % (gmpy.mpz(i)*gmpy.mpz(j)),
## print
##
##
## ...
|
by: zakad |
last post by:
python 2.5.2
ubuntu 8.04 LTS
(1) I find that python/gmpy is about 3 times slower than c++/gmp.
Is this the general experience, or am I doing something wrong?
(2) I am unable to understand the...
|
by: |
last post by:
Hi,
I just stumbled upon the following issue (I am running Debian):
$ python
Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13)
on linux2
Type "help", "copyright", "credits" or "license" for...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
| |