Skip to content

cmath.nan docs: Equivalent to float('nan') #137871

@KardoPaska

Description

@KardoPaska

Documentation

Hello Friends!

Perhaps cmath.nan description can be more like math.nan?

Perhaps some insight to the intended nuances could benefit the description? Compare and contrast?

In the context of NaNs, the meaning of the word "equivalent" is quite nuanced.

Best!

https://docs.python.org/3/library/cmath.html#cmath.nan

cmath.nan
A floating-point “not a number” (NaN) value. Equivalent to float('nan').

Added in version 3.6.

https://docs.python.org/3/library/math.html#math.nan

math.nan
A floating-point “not a number” (NaN) value. Equivalent to the output of float('nan'). 
Due to the requirements of the [IEEE-754 standard](https://en.wikipedia.org/wiki/IEEE_754), 
math.nan and float('nan') are not considered to equal to any other numeric value, including themselves. 
To check whether a number is a NaN, use the 
[isnan()](https://docs.python.org/3/library/math.html#math.isnan) function to test for NaNs instead of is or ==. Example:

import math
math.nan == math.nan
False
float('nan') == float('nan')
False
math.isnan(math.nan)
True
math.isnan(float('nan'))
True
Added in version 3.5.

Changed in version 3.11: It is now always available.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesdocsDocumentation in the Doc direasystdlibPython modules in the Lib dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions