For parts of the .NET Framework that are implemented in C #, it is easiest to view them using http://referencesource.microsoft.com/ . For the rest, you either need to download a copy of SSCLI, or browse the coreclr repository on GitHub.
A free e-book has been published that attempts to explain the inner workings of most of SSCLI2, which is a smaller version of .NET 2.
InternalCall handled by the runtime using the mappings defined in the ecalllist.h file in coreclr or in ecall.cpp for sscli, For example, Math.Round is displayed as:
// snip FCFuncStart(gMathFuncs) FCIntrinsic("Sin", COMDouble::Sin, CORINFO_INTRINSIC_Sin) FCIntrinsic("Cos", COMDouble::Cos, CORINFO_INTRINSIC_Cos) FCIntrinsic("Sqrt", COMDouble::Sqrt, CORINFO_INTRINSIC_Sqrt) FCIntrinsic("Round", COMDouble::Round, CORINFO_INTRINSIC_Round) // snip
If we look at the COMDouble class, the implementation of which we can find in comfloat.cpp , we see the Math.Round code:
/*====================================Round===================================== ** ==============================================================================*/ FCIMPL1_V(double, COMDouble::Round, double x) FCALL_CONTRACT; // If the number has no fractional part do nothing // This shortcut is necessary to workaround precision loss in borderline cases on some platforms if (x == (double)((INT64)x)) { return x; } // We had a number that was equally close to 2 integers. // We need to return the even one. double tempVal = (x + 0.5); double flrTempVal = floor(tempVal); if ((flrTempVal == tempVal) && (fmod(tempVal, 2.0) != 0)) { flrTempVal -= 1.0; } return _copysign(flrTempVal, x); FCIMPLEND
Mitch source share