我测试了PHP中NAN
常量中的is_numeric
函数和给定的结果
is_numeric(NAN); // TRUE
但 NAN 的意思是“不是数字”。为什么函数 is_numeric
返回 true
?
我知道 NAN 是 float
类型。但是在测试下面两种情况时,结果是不同的:
is_float(NAN) // true
filter_var(NAN, FILTER_VALIDATE_FLOAT)// false
为什么会发生?
对不起,我的英语不好
最佳答案
NAN
是一个特殊的常量。它必须包含一些值,所以它包含一个float
datatype
var_dump(NAN); // float(NAN);
问题是 filter_var
不是在比较数据类型,而是在寻找数字,NAN
is not .
Some numeric operations can result in a value represented by the constant NAN. This result represents an undefined or unrepresentable value in floating-point calculations. Any loose or strict comparisons of this value against any other value, including itself, will have a result of FALSE.
Because NAN represents any number of different values, NAN should not be compared to other values, including itself, and instead should be checked for using is_nan().
关于php - 为什么 is_numeric(NAN) 返回 TRUE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40554990/