469,270 Members | 1,056 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

+/-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 68260
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,

thanks for your hints.

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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

39 posts views Thread by Marco Aschwanden | last post: by
89 posts views Thread by Radioactive Man | last post: by
28 posts views Thread by Grant Edwards | last post: by
108 posts views Thread by Bryan Olson | last post: by
5 posts views Thread by Peter Hansen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.