Python Forum
Why is bool(float("nan")) == True?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is bool(float("nan")) == True?
#5
(Dec-30-2023, 06:50 PM)DeaD_EyE Wrote: Due to the requirements of the IEEE-754 standard, math.nan and float('nan') are not considered to equal to any other numeric value, including themselves.
>>> float('nan') == float('nan')
False
>>> 
>>> x = float('nan')
>>> x == x
False
>>> 
That's because you can never tell where a NaN value comes from, and the IEEE-754 format allows several NaN values.
RockBlok likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply


Messages In This Thread
RE: Why is bool(float("nan")) == True? - by Gribouillis - Dec-31-2023, 09:21 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020