为什么typeNNN会返回“数字”? [英] Why does typeof NaN return 'number'?

查看:92
本文介绍了为什么typeNNN会返回“数字”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于好奇。

typeof NaN 是数字似乎不合逻辑。就像 NaN === NaN NaN == NaN 顺便返回false。这是javascript的特点之一,还是有理由这样做?

It doesn't seem very logical that typeof NaN is number. Just like NaN === NaN or NaN == NaN returning false, by the way. Is this one of the peculiarities of javascript, or would there be a reason for this?

编辑:感谢您的回答。尽管让人们感到高兴并不容易。阅读答案和wiki我理解得更多,但仍然是一句话,如

thanks for your answers. It's not an easy thing to get ones head around though. Reading answers and the wiki I understood more, but still, a sentence like


与NaN的比较总是会返回无序结果,即使比较与自己。比较谓词是信令或非信令,信令版本表示这种比较的无效例外。等式和不等式谓词是非信令的,因此x = x返回false可用于测试x是否是安静的NaN。

A comparison with a NaN always returns an unordered result even when comparing with itself. The comparison predicates are either signaling or non-signaling, the signaling versions signal an invalid exception for such comparisons. The equality and inequality predicates are non-signaling so x = x returning false can be used to test if x is a quiet NaN.

让我头晕目眩。如果有人能用人类(而不是数学家)的可读语言翻译,我会感激不尽。

just keeps my head spinning. If someone can translate this in human (as opposed to, say, mathematician) readable language, I would be gratefull.

推荐答案

它意思不是数字。它不是javascript的特性,而是普通的计算机科学原理。

It means Not a Number. It is not a peculiarity of javascript but common computer science principle.

来自 http://en.wikipedia.org/wiki/NaN


有三种操作返回NaN的

There are three kinds of operation which return NaN:

使用NaN作为至少一个操作数的操作

Operations with a NaN as at least one operand

不确定表单


  • 分区0/0,∞/∞,∞/-∞,-∞/∞和-∞/-∞

  • 乘法0×∞和0×-∞

  • 功率1 ^∞

  • 加法∞+( -∞),( - ∞)+∞和等效减法。

  • The divisions 0/0, ∞/∞, ∞/−∞, −∞/∞, and −∞/−∞
  • The multiplications 0×∞ and 0×−∞
  • The power 1^∞
  • The additions ∞ + (−∞), (−∞) + ∞ and equivalent subtractions.

复杂结果的实际操作:


  • 负数的平方根

  • 负数的对数

  • 90度(或π/ 2)的奇数倍的正切值弧度)

  • 数字小于-1或
    大于+1的反正弦或余弦。

  • The square root of a negative number
  • The logarithm of a negative number
  • The tangent of an odd multiple of 90 degrees (or π/2 radians)
  • The inverse sine or cosine of a number which is less than −1 or greater than +1.

所有这些值可能不一样。对NaN的简单测试是测试 value == value 是否为假。

All these values may not be the same. A simple test for a NaN is to test value == value is false.

这篇关于为什么typeNNN会返回“数字”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆