473,507 Members | 6,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

gmpy floating point exception

Hi,

I am experiencing some trouble with gmpy v1.01.
Multiplying an mpq with inf results in a floating point exception that
exits python. Has this already been fixed in newer gmpy versions?

~ $ python
Python 2.4.3 (#1, Mar 26 2007, 00:32:54)
[GCC 4.1.1 (Gentoo 4.1.1-r3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>from gmpy import mpq as Rational
a=Rational(2,3)
b=1.0e99999
b
inf
>>int(b)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: cannot convert float infinity to long
>>a+b
Floating point exception
~ $
BTW.
1) What is the best way to test for inf regardless of type?
2) Is there any inf type around with
a + inf == inf
inf a (as long as a != inf)
etc.
that works with any other type?

Thanks in advance

Martin
Mar 29 '07 #1
2 2639
Martin Manns <mm****@gmx.netwrote:
Hi,

I am experiencing some trouble with gmpy v1.01.
Multiplying an mpq with inf results in a floating point exception that
exits python. Has this already been fixed in newer gmpy versions?
No, I can reproduce the problem (on a Mac with an Intel CPU) with the
current version, 1.02. I will have no time to work for a fix until (I
hope) next week, though (spending a long weekend hitch-hiking).
BTW.
1) What is the best way to test for inf regardless of type?
No, 'inf' is in fact not portable among different builds of Python for
different CPUs, in general.
2) Is there any inf type around with
a + inf == inf
inf a (as long as a != inf)
etc.
that works with any other type?
You mean something like:

class inf(object):
def __radd__(self, other): return self
def __gt__(self, other): return self is not other
# etc
inf = inf()

....?
Alex
Mar 29 '07 #2
On Thu, 29 Mar 2007 00:57:03 -0700
al***@mac.com (Alex Martelli) wrote:
Martin Manns <mm****@gmx.netwrote:
2) Is there any inf type around with
a + inf == inf
inf a (as long as a != inf)
etc.
that works with any other type?

You mean something like:

class inf(object):
def __radd__(self, other): return self
def __gt__(self, other): return self is not other
# etc
inf = inf()
Actually, I meant something a bit more sophisticated:
a=inf()
b=inf()
c=-inf()
d=1e99999
e=numpy.float64(1e99999)
f=gmpy.mpq(1,2)

a b OverflowError (AmbiguousValueError?)
a == b OverflowError (AmbiguousValueError?)
a + b inf (New inf instance)
a + c OverflowError (AmbiguousValueError?)
a + d a
max(a,b) inf (New inf instance)
max(a,c) a
max(a,d) a
max(a,b) == a OverflowError (AmbiguousValueError?)
max(a,b) == b OverflowError (AmbiguousValueError?)
max(a,b) a OverflowError (AmbiguousValueError?)
max(a,b) >= a True (if somehow possible)
max(a,b) < a False (if somehow possible)
a is b False
a c True
a == -a False
a == -c OverflowError (AmbiguousValueError?)
a d True
a e True
c f False

The idea is a class that permits non-ambiguous comparisons but throws
exceptions if ambiguous comparisons are made. Since I think that
setting up such a class involves quite some effort (especially
considering things such as a + a) I just wanted to know if something
similar is already around. I am aware of the PEP 326 but I feel that it
does not really address the problem.

Martin
Mar 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3437
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:...
1
3315
by: Andrew Straw | last post by:
I'm running into trouble when calling a 3rd party library (the Intel IPP library to do some fast math on a P4 processor). This is on debian linux 2.6.7 using python 2.3.4. I've been using Pyrex...
11
1744
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...
10
6691
by: Vinny | last post by:
I have a few floating point questions/issues I wish to ask. An answer or discussion would be nice too :) Any links discussion the subject would be nice too.. 1. How do I generate an underflow...
3
2417
by: mensanator | last post by:
Since the following discussion took place (unresolved), ...
4
2823
by: jacob navia | last post by:
Hi people I continue to work in the tutorial for lcc-win32, and started to try to explain the floating point flags. Here is the relevant part of the tutorial. Since it is a difficult part, I...
3
2214
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 ## ## ## ...
39
3519
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody...
7
1400
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...
0
7220
marktang
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,...
0
7371
jinu1996
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...
1
7023
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...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
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...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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 ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.