最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【整理】PHP中的NaN是什么意思

PHP crifan 6699浏览 0评论

【背景】

折腾:

【整理】PHP中的三个等于号===的含义

期间,看到有个NaN,没见过,要去搞懂含义。

 

【折腾过程】

1.搜:

PHP NaN

PHP NaN含义

what is php nan

参考:

PHP: is_nan – Manual

“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.

JS中如何判断null、undefined与NaN-php程序员的笔记

 

【总结】

貌似就是:

NaN==Not a Number的首字母缩写,含义是:合法数值。

其中这些合法数值,主要是哪些,可以用浮点数去表示(但是未必一定是对应着某个具体的浮点数值)。

 

注:

JS中也有个类似的函数:isNaN

并且:“isNaN() 函数通常用于检测 parseFloat() 和 parseInt() 的结果,以判断它们表示的是否是合法的数字。当然也可以用 isNaN() 函数来检测算数错误,比如用 0 作除数的情况。”

 

暂时没搞懂:

为何PHP中会有个is_nan,本意是用来干啥的,主要在何种情况下使用。

转载请注明:在路上 » 【整理】PHP中的NaN是什么意思

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.164 seconds, using 22.10MB memory