【背景】
折腾:
期间,看到有个NaN,没见过,要去搞懂含义。
【折腾过程】
1.搜:
PHP NaN
PHP NaN含义
what is php nan
参考:
“is_nan — 判断是否为合法数值”
还是没懂NaN是啥含义。
看到评论中的解释:nan/"not a number" is not meant to see if the data type is numeric/textual/etc..
NaN is actually a set of values which can be stored in floating-point variables, but dont actually evaluate to a proper floating point number.
The floating point system has three sections: 1 bit for the sign (+/-), an 8 bit exponent, and a 23 bit fractional part.
There are rules governing which combinations of values can be placed into each section, and some values are reserved for numbers such as infinity. This leads to certain combinations being invalid, or in other words, not a number.
【总结】
貌似就是:
NaN==Not a Number的首字母缩写,含义是:合法数值。
其中这些合法数值,主要是哪些,可以用浮点数去表示(但是未必一定是对应着某个具体的浮点数值)。
注:
JS中也有个类似的函数:isNaN
并且:“isNaN() 函数通常用于检测 parseFloat() 和 parseInt() 的结果,以判断它们表示的是否是合法的数字。当然也可以用 isNaN() 函数来检测算数错误,比如用 0 作除数的情况。”
暂时没搞懂:
为何PHP中会有个is_nan,本意是用来干啥的,主要在何种情况下使用。