472,353 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

+/-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 68586
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Marco Aschwanden | last post by:
Hi I don't have to talk about the beauty of Python and its clear and readable syntax... but there are a few things that striked me while...
89
by: Radioactive Man | last post by:
In python 2.3 (IDLE 1.0.3) running under windows 95, I get the following types of errors whenever I do simple arithmetic: 1st example: >>> 12.10...
28
by: Grant Edwards | last post by:
I finally figured out why one of my apps sometimes fails under Win32 when it always works fine under Linux: Under Win32, the pickle module only...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information...
2
by: Russell Smith | last post by:
Timestamps support infinity. However if appears dates do not. When timestamps are cast to dates, there is no output. Is this an acceptable...
5
by: Peter Hansen | last post by:
I'm investigating a puzzling problem involving an attempt to generate a constant containing an (IEEE 754) "infinity" value. (I understand that...
2
by: Pierre Rouleau | last post by:
Hi all, When using Python 2.4.x on a Win32 box, marshal.loads(marshal.dumps(1e66666)) returns 1.0 instead of infinity as it should and does...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.