为什么System.Math拥有的extern方法SIN,COS等? [英] Why System.Math has extern methods for Sin, Cos, etc?

查看:114
本文介绍了为什么System.Math拥有的extern方法SIN,COS等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[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.

这篇关于为什么System.Math拥有的extern方法SIN,COS等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆