C/C++ NaN constant (literal)?

后端 未结 5 867
孤独总比滥情好
孤独总比滥情好 2020-11-29 21:20

Is this possible to assign a NaN to a double or float in C/C++? Like in JavaScript you do: a = NaN. So later you can chec

5条回答
  •  时光取名叫无心
    2020-11-29 21:48

    This can be done using the numeric_limits in C++:

    http://www.cplusplus.com/reference/limits/numeric_limits/

    These are the methods you probably want to look at:

    infinity()  T   Representation of positive infinity, if available.
    quiet_NaN() T   Representation of quiet (non-signaling) "Not-a-Number", if available.
    signaling_NaN() T   Representation of signaling "Not-a-Number", if available.
    

提交回复
热议问题