为什么将无穷大打印为“ 8”?在Windows 10控制台中? [英] Why is infinity printed as "8" in the Windows 10 console?
问题描述
我正在测试除法返回的内容,包括零,即 0/1
, 1/0
和 0/0
。为此,我使用了类似于以下内容的东西:
I was testing what was returned from division including zeroes i.e. 0/1
, 1/0
and 0/0
. For this I used something similar to the following:
Console.WriteLine(1d / 0d);
但是此代码显示 8
而不是 Infinity
或其他字符串常量,例如 PositiveInfinity
。
However this code prints 8
not Infinity
or some other string constant like PositiveInfinity
.
为了完整性下面所有的打印 8
:
For completeness all of the following print 8
:
Console.WriteLine(1d / 0d);
double value = 1d / 0d;
Console.WriteLine(value);
Console.WriteLine(Double.PositiveInfinity);
和 Console.WriteLine(Double.NegativeInfinity);
打印 -8
。
为什么此无穷大打印8?
Why does this infinity print 8?
对于那些似乎认为这是一个无穷大符号而不是八个以下程序的人:
For those of you who seem to think this is an infinity symbol not an eight the following program:
Console.WriteLine(1d / 0d);
double value = 1d / 0d;
Console.WriteLine(value);
Console.WriteLine(Double.PositiveInfinity);
Console.WriteLine(8);
输出:
推荐答案
请确保浮点值为 + Infinity
。浮点数除以零的分子为正,如果浮点数除以零的分子为负,则-无穷大
c $ c>如果浮点除法的分子和分母均为零。这就是 IEEE754浮点规范,这是C#所使用的。
Be assured that the floating point value is +Infinity
if the numerator of a floating point division by zero is positive, -Infinity
if the numerator of a floating point division by zero is negative, and NaN
if the numerator and denominator of a floating point division are both zero. That's in the IEEE754 floating point specification, which is what C# uses.
在您的情况下,控制台将无穷大符号(有时在印刷上用水平8 —∞表示)转换为垂直8。
In your case, the console is converting the infinity symbol (which is sometimes represented typographically as a horizontal 8 — ∞) to a vertical 8.
这篇关于为什么将无穷大打印为“ 8”?在Windows 10控制台中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!