On the range of the double
type:
double dbl1 = (double.MinValue + double.MaxValue) + double.MaxValue;
double dbl2 = double.MinValue + (double.MaxValue + double.MaxValue);
The first one is double.MaxValue
, the second one is double.Infinity
On the precision of the double
type:
double dbl1 = (double.MinValue + double.MaxValue) + double.Epsilon;
double dbl2 = double.MinValue + (double.MaxValue + double.Epsilon);
Now dbl1 == double.Epsilon
, while dbl2 == 0
.
And on literally reading the question :-)
In checked
mode:
checked
{
int i1 = (int.MinValue + int.MaxValue) + int.MaxValue;
}
i1
is int.MaxValue
checked
{
int temp = int.MaxValue;
int i2 = int.MinValue + (temp + temp);
}
(note the use of the temp
variable, otherwise the compiler will give an error directly... Technically even this would be a different result :-) Compiles correctly vs doesn't compile)
this throws an OverflowException
... The results are different :-) (int.MaxValue
vs Exception
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…