473,372 Members | 894 Online

# +/-infinity in Python?

Hi.

Is there anything like +infinity and -infinity available in Python, and
can it be used in comparisons together with int or float numbers?

Regards
Andreas
Jul 18 '05 #1
4 68715
Andreas Neudecker wrote:
Is there anything like +infinity and -infinity available in Python, and
can it be used in comparisons together with int or float numbers?

To lazy to look it up, so let's try:
oo = float("infinity")
noo = float("-infinity")
oo/noo nan oo/2 inf noo/2 -inf 10e10 > oo False 10e10 < oo True

:-)

Peter
Jul 18 '05 #2
In article <bp*************@news.t-online.com>, Peter Otten wrote:
Andreas Neudecker wrote:
Is there anything like +infinity and -infinity available in Python, and
can it be used in comparisons together with int or float numbers?

To lazy to look it up, so let's try:

[snip]

Looking it up might be good, though... See, for example, PEP 754,
"IEEE 754 Floating Point Special Values":

http://www.python.org/peps/pep-0754.html

The problem is that the expression float('infinity') works on some
platforms, along with float('Inf'), but, as the PEP points out, on
many systems you'll just get an error. You could also try stuff like
float(1e3000).

So, my response to the original question would be "sort of" -- since
it's there, but it's not particularly reliable. Let's just hope that
PEP 754 (or something similar) is accepted; infinity _is_ certainly
useful...

--
Magnus Lie Hetland "In this house we obey the laws of
http://hetland.org thermodynamics!" Homer Simpson
Jul 18 '05 #3
Andreas Neudecker <a.*********@uni-bonn.de> writes:
Hi.

Is there anything like +infinity and -infinity available in Python, and can it
be used in comparisons together with int or float numbers?

The newest version of numarray and scipy should offer the functionality you
want (at least for supported platforms).

'as
Jul 18 '05 #4
Hello Peter, Magnus,

I will read the PEPs first, because I need compatibility at least for
Linux and Windows ...

Kind regards
Andreas
Andreas Neudecker wrote:
Hi.

Is there anything like +infinity and -infinity available in Python, and
can it be used in comparisons together with int or float numbers?

Regards
Andreas

Jul 18 '05 #5

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