Yes for double numbers it's actually external code:
[System.Security.SecuritySafeCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern double Ceiling(double a);
That means that the method is actually implemented in the CLR, written in C++. The lookup table is located in clr/src/vm/ecalllist.h. The section that's relevant to Math.Ceiling() looks like this:
FCFuncStart(gMathFuncs)
...
FCFuncElement("Log10", COMDouble::Log10)
FCFuncElement("Ceiling", COMDouble::Ceil)
FCFuncElement("SplitFractionDouble", COMDouble::ModFDouble)
...
CLR implementation calls native function:
FCIMPL1_V(double, COMDouble::Ceil, double d)
WRAPPER_CONTRACT;
STATIC_CONTRACT_SO_TOLERANT;
return (double) ceil(d);
FCIMPLEND
Here is an implementation from <cmath>
:
#include <cmath>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
double ceil(double x)
{
double result;
int save_round = std::fegetround();
std::fesetround(FE_UPWARD);
result = std::rint(x); // or std::nearbyint
std::fesetround(save_round);
return result;
}
See also Hans answer for more details.