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 1891
Alex Martelli <al***@mail.com cast.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: what is the better replacement solution
for manipulating long numbers. I want to do long numbers
exponentiations. Thanks in advance for your answers.
JP
|
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 program operates as it should,
which I guess is why it's a warning. Is there some reason why I shouldn't
use gmpy numbers with relational operators? Is this warning something
that can safely be ignored?
|
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 check it at
all). I can't reach sourceforge at the moment, so I have meanwhile put
the exe file up at:
http://www.aleax.it/Python/gmpy-1.0.win32-py2.4.exe
Users of both gmpy and python 2.4 on windows are invited to dowload and
install this,...
|
by: mensanator |
last post by:
Since the following discussion took place (unresolved),
<http://groups.google.com/group/comp.lang.python/browse_frm/thread/c3bd08ef3e4c478a/2b54deb522c9b9d9?lnk=st&q=divm()+memory+leak+group:comp.lang.python+author:mensanator&rnum=1&hl=en#2b54deb522c9b9d9>
I've kept it in the back of my mind as I've been
learning to use the base gmp library in c. Now I believe
I know what the problem is.
First, divm() is not a gmp function. It is a...
|
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
version (one thing I must still look at is divm's behavior when its args
are not mutually prime). It currently compiles w/o warnings, and passes
all of its 1040+ tests, w/the current release of GMP (4.1.4), Python
(2.4.2), MacOSX (10.4.3), XCode...
| |
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 previously
installed (I'm told the one that comes with fink works; I installed my
own from sources, from the GMP's site at swox.com), and they're .tar.gz
packages requiring unpacking with tar xzf from the Terminal -- so, not
very Mackish -- but...
|
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
##
##
## 0 0 0 0 0 0 0 0 0 0
## 0 1 2 3 1 5 6 7 2 9
|
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 following error in conversion from float() to gmpy.mpf() or how to avoid it:
import gmpy
|
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 more information.
1
Traceback (most recent call last):
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |