- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用生成器创建对象,如下所示:
function* Thing() {
var x = 0;
while (x < 3) {
var rules = [{arr: [1, 2, 3]}, {arr: [1]}, {arr: []}];
yield {
arrayMinimum: Math.min(...rules[x].arr)
}
x++
}
}
var create = Thing();
console.log(create.next().value)
console.log(create.next().value)
console.log(create.next().value) // { arrayMinimum: Infinity } ???
为什么 Math.min(...[]) === Infinity
?
奖金混淆:Math.max(...[]) === -Infinity
???
最佳答案
这是因为 (...[])
指定的参数列表是空参数列表——也就是说,您正在执行 Math.min()
没有参数。
EMCAScript spec for Math.min
states :
If no arguments are given, the result is +∞.
(不出所料,它有 a similar statement for Math.max
。)
关于javascript - 在 Javascript 中,为什么空数组的最小值是无穷大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43053848/
任何数字减去它本身应该是 0,对吗? 3 - 3 === 0 那为什么 Infinity - Infinity === NaN 因为 typeof Infinity 是 'number': 最佳答案
我有一个可能为零的数字。我除以那个数字所以我想测试它是否为零以防止 NaN 和无穷大。由于除法中的舍入误差,我是否仍可能创建 NaN/无穷大? double x; // might be zero d
我使用carrierwave 和mini_magick 上传图片。在开发中一切都很好,但在生产中它引发了 FloatDomainError (Infinity)当我尝试上传图片时。我在同一台服务器上托
我有一个递归函数,它从一组边生成路径列表。但是,有时由于图形的性质,它会进入循环并生成一个字典,其中在列表中包含无限循环符号 [...],例如: {('a', 'b'): [[1, 2, 8, 9,
我正在摆弄 JavaScript 中的按位运算符,我发现有一件事值得注意。 bitwise or operator返回1如果两个输入位之一是 1 作为输出位。这样做x | 0总是返回x ,因为| 0没
我检查二叉树是否是 BST 的解决方案如下: def is_BST(node): if node is None: return False stack = [(node, -floa
给定(Python3): >>> float('inf') == Decimal('inf') True >>> float('-inf') >> float('-inf') >> Decimal('
我正在尝试使用 scikit learn 拟合一个简单的机器学习模型。在这条线上: clf.fit(features, labels) 我得到一个熟悉的错误: Input contains NaN,
我有一个数据集,它是 2 个浮点类型数字的比率。有些值具有 inf 表示无穷大(除以零)的情况。如何使用 pd.qcut/pd.cut 和 inf 值? 我的数据可以访问 here . q = pd.
好的,我知道之前有人用一个有限的缩放示例问过这个问题 [-1, 1]间隔 [a, b] Different intervals for Gauss-Legendre quadrature in num
案例:我们有一个运行 bash 脚本的 docker 容器,该脚本需要永远“阻塞”(因为它为另一个容器公开了一个卷,但有时我们需要这样做还有其他原因)。 我当时认为这可以工作: exec sleep
我是一名优秀的程序员,十分优秀!