Float nan equality

I had a bug where nan floats failed to compare equal because there seems to be more than one nan value and comparison seems to be binary based. How about we make float eq test if both are math. Isnan? -- Arkadiusz Bulski --

On 4 October 2016 at 21:32, Arek Bulski <arek.bulski@gmail.com> wrote:
I had a bug where nan floats failed to compare equal because there seems to be more than one nan value and comparison seems to be binary based.
"NaN != NaN" is part of the definition of IEEE 754 floats: https://en.wikipedia.org/wiki/NaN#Floating_point That's why it returns False even if you compare a specific NaN instance with itself: >>> x = float("nan") >>> x == x False If you need a kinda-like-NaN value that provides reflexive equality, then Python's None singleton is a better fit. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On 4 October 2016 at 21:32, Arek Bulski <arek.bulski@gmail.com> wrote:
I had a bug where nan floats failed to compare equal because there seems to be more than one nan value and comparison seems to be binary based.
"NaN != NaN" is part of the definition of IEEE 754 floats: https://en.wikipedia.org/wiki/NaN#Floating_point That's why it returns False even if you compare a specific NaN instance with itself: >>> x = float("nan") >>> x == x False If you need a kinda-like-NaN value that provides reflexive equality, then Python's None singleton is a better fit. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (2)
-
Arek Bulski
-
Nick Coghlan