473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 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 68720
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 learning Python. I have collected those thoughts. I am...
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 + 8.30 20.399999999999999 >>> 1.1 - 0.2...
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 works with a subset of floating point values. In...
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 about the extended slice that the slice object would...
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 option or not? Below are a number of examples...
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 special float values are a "platform-dependent...
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 under Python 2.5 (also running on Win32 ). This...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.