operator overload
-
look at the lines: double x = double.MaxValue; double y = double.MaxValue; double what = (x+y)-y; if c# select the double operator+(double,double), then what should be "PositiveInfinity"; but it is double.MaxValue! Why does this happen? Is there a decimal operator + (double,double)? If there is, then there should be no " double operator +(double,double)". Who knows the fact? Please help. Thanks.
-
look at the lines: double x = double.MaxValue; double y = double.MaxValue; double what = (x+y)-y; if c# select the double operator+(double,double), then what should be "PositiveInfinity"; but it is double.MaxValue! Why does this happen? Is there a decimal operator + (double,double)? If there is, then there should be no " double operator +(double,double)". Who knows the fact? Please help. Thanks.
-
Here is the compiled code:
x = double.MaxValue; 00000020 mov dword ptr [ebp-10h],0FFFFFFFFh 00000027 mov dword ptr [ebp-0Ch],7FEFFFFFh y = double.MaxValue; 0000002e mov dword ptr [ebp-18h],0FFFFFFFFh 00000035 mov dword ptr [ebp-14h],7FEFFFFFh z = x + y - y; 0000003c fld qword ptr [ebp-10h] 0000003f fadd qword ptr [ebp-18h] 00000042 fsub qword ptr [ebp-18h] 00000045 fstp qword ptr [ebp-20h]
The actual calculation is done in the FPU, storing the result of the first calculation internally. It looks like the datatype used internally can handle larger values than a double, as the result of the calculation is correct. --- b { font-weight: normal; }