[MethodImpl(MethodImplOptions.InternalCall)]
public static extern double Sin(double a);
What are the reasons for this?
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern double Sin(double a);
What are the reasons for this?
MethodImplOptions.InternalCall means the method is implemented natively by the common language runtime. It makes sense for mathematical operations as they are usually heavily optimized for the target platform. For instance, in x86 architecture, there is a single instruction that computes sine and cosine. A managed implementation is unlikely to be able to directly utilize such instructions.
The implementation is done in native. This is not just for Sin, look also at the common string operations.
The CLR is aware of such methods, and it maintains a "call table". When it sees the call from Math.Sin it redirects it to the native implementation by "lookup" into the call table. If you want to find more, search for ecall.cpp in the rotor sources, or go directly here (google code search).