Issue 6567: Make inf be almost equal to inf (original) (raw)

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 float('inf'). 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 "inf". 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 calculations. 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
[lucaspmelo] > 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 assertAlmostEquals.
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.
History
Date User Action Args
2022-04-11 14:56:51 admin set github: 50816
2009-09-13 16:40:29 michael.foord set status: open -> closedresolution: wont fix -> acceptedmessages: +
2009-07-26 10:28:51 mark.dickinson set messages: +
2009-07-25 20:29:04 michael.foord set messages: +
2009-07-25 19:52:12 mark.dickinson set messages: +
2009-07-25 17:34:15 gregory.p.smith set nosy: + gregory.p.smithmessages: +
2009-07-25 13:23:19 michael.foord set messages: +
2009-07-25 13:20:01 ezio.melotti set nosy: + mark.dickinson
2009-07-25 12:56:51 lucaspmelo set status: closed -> opentype: behavior -> enhancementmessages: + title: Isn't inf almost equal to inf? -> Make inf be almost equal to inf
2009-07-25 00:26:54 michael.foord set status: open -> closednosy: + michael.foordmessages: + resolution: wont fix
2009-07-24 23:58:02 eric.smith set nosy: + eric.smith
2009-07-24 22:07:15 lucaspmelo set type: behavior
2009-07-24 22:06:58 lucaspmelo set components: + Tests
2009-07-24 22:06:29 lucaspmelo set versions: + Python 3.2
2009-07-24 22:05:35 lucaspmelo create