[MethodImpl(MethodImplOptions.InternalCall)]
public static extern double Sin(double a);
什么原因呢?
What are the reasons for this?
MethodImplOptions.InternalCall
表示该方法是由公共语言运行库本地实现的。这是有道理的数学运算,因为他们通常是严重目标平台进行了优化。例如,在x86架构,有一个单一的指令,计算正弦和余弦值。被管理的实现是不可能的,以便能够直接利用这样的指令
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.