gmpy floating point exception

M

Martin Manns

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.Traceback (most recent call last):
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
 
A

Alex Martelli

Martin Manns said:
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
 
M

Martin Manns

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()[/QUOTE]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top