This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Make inf be almost equal to inf
Type: enhancement Stage:
Components: Tests Versions: Python 3.2, Python 2.6
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, gregory.p.smith, lucaspmelo, mark.dickinson, michael.foord
Priority: normal Keywords:

Created on 2009-07-24 22:05 by lucaspmelo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (9)
msg90902 - (view) Author: Lucas Prado Melo (lucaspmelo) Date: 2009-07-24 22:05
When we use TestCase.assertAlmostEqual to compare two float('inf')
objects, the result is that float('inf') is not almost equal to
I believe this is a bug. I tested against r74195 of Python 3.2 and
against Python 2.6.2.
msg90906 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-07-25 00:26
Uhm... they may or may not be almost equal, but probably not.
Comparisons on them are defined to be undefined so you're using the
wrong thing to test them. Use assertTrue and math.isinf instead.
msg90921 - (view) Author: Lucas Prado Melo (lucaspmelo) Date: 2009-07-25 12:56
I would like to ask as a feature request that "inf" be almost equal to
I wrote a program with a timeline class that had a method to tell the
time of the last event registered into it such that some events would be
positioned at the infinite when they wouldn't occur. I did generic tests
that would receive any output from this method and compare to the
expected result through unittest.TestCase.assertAlmostEqual(). Notice,
though, that I couldn't just pick assertEqual() to do this job because
the time of the last event would be defined through a series of
Despite that, I believe that everything which is equal to anything else
would definitely be almost equal too. Thus, it would be nice to check
for equality before checking for almost-equality to define whether two
objects are almost equal.
msg90923 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-07-25 13:23
Hmm... I guess equality does imply almost-equals. I'll make and document
the change that objects that compare equal will also compare almost equal.
msg90928 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-07-25 17:34
good catch.  thanks!
msg90930 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-07-25 19:52
> I would like to ask as a feature request that "inf" be almost equal to
> "inf".

Sounds reasonable to me.  Just so long as float('-inf') isn't almost equal 
to float('inf');  that would be weird.

One could almost make a case for values very close to the upper limit of 
the floating-point range being almost equal to float('inf'), but I think 
that's taking things a bit too far.
msg90931 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-07-25 20:29
All I'm proposing to do is add a short circuit equality test to
msg90936 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-07-26 10:28
Sounds good to me.
msg92571 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-09-13 16:40
Committed revision 74780.
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50816
2009-09-13 16:40:29michael.foordsetstatus: open -> closed
resolution: wont fix -> accepted
messages: + msg92571
2009-07-26 10:28:51mark.dickinsonsetmessages: + msg90936
2009-07-25 20:29:04michael.foordsetmessages: + msg90931
2009-07-25 19:52:12mark.dickinsonsetmessages: + msg90930
2009-07-25 17:34:15gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg90928
2009-07-25 13:23:19michael.foordsetmessages: + msg90923
2009-07-25 13:20:01ezio.melottisetnosy: + mark.dickinson
2009-07-25 12:56:51lucaspmelosetstatus: closed -> open
type: behavior -> enhancement
messages: + msg90921

title: Isn't inf almost equal to inf? -> Make inf be almost equal to inf
2009-07-25 00:26:54michael.foordsetstatus: open -> closed

nosy: + michael.foord
messages: + msg90906

resolution: wont fix
2009-07-24 23:58:02eric.smithsetnosy: + eric.smith
2009-07-24 22:07:15lucaspmelosettype: behavior
2009-07-24 22:06:58lucaspmelosetcomponents: + Tests
2009-07-24 22:06:29lucaspmelosetversions: + Python 3.2
2009-07-24 22:05:35lucaspmelocreate