(乔恩斯基特今日报道的来源)认为:
Math.Max(1f, float.NaN) == NaN
new[] { 1f, float.NaN }.Max() == 1f
为什么?
编辑:用双也是同样的问题。
same issue with double also!
推荐答案
正如其他已经公布,我啾啾的一个的那种为什么 - 在它使用 IComparable的
的记录。
As others have posted, I tweeted one sort of "why" - in that it's using IComparable
as documented.
这只是导致了另一个为什么虽然。特别是:
That just leads to another "why" though. In particular:
Console.WriteLine(Math.Max(0, float.NaN)); // Prints NaN
Console.WriteLine(0f.CompareTo(float.NaN)); // Prints 1
的第一行表明,NaN被认为是大于0的第二行表明,0被认为是大于NaN的。 (这些都不可以报告这种比较是没有意义的,当然,结果。)
The first line suggests that NaN is regarded as being greater than 0. The second line suggests that 0 is regarded as being greater than NaN. (Neither of these can report the result of "this comparison doesn't make sense", of course.)
我看到所有的答复鸣叫,当然也包括这些 2 :
I have the advantage of seeing all the reply tweets, of course, including these two:
这似乎是不寻常的,但是这是正确的答案。数组MAX()是NaN当且仅当所有的元素都为NaN。见IEEE 754R。
It may seem unusual, but that's the right answer. max() of an array is NaN iff all elements are NaN. See IEEE 754r.
此外,Math.Max使用IEEE 754R整体排序predicate,它指定为NaN与他人的相对排序。
Also, Math.Max uses IEEE 754r total ordering predicate, which specifies relative ordering of NaN vs. others.
相关推荐
最新文章