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);
However this code prints 8
not Infinity
or some other string constant like PositiveInfinity
.
For completeness all of the following print 8
:
Console.WriteLine(1d / 0d);
double value = 1d / 0d;
Console.WriteLine(value);
Console.WriteLine(Double.PositiveInfinity);
And Console.WriteLine(Double.NegativeInfinity);
prints -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);
Outputs:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…