作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在反射器中寻找 Atan2 的 .NET 实现并找到了以下行:
public static extern double Atan2(double y, double x);
这并不奇怪,因为用 native 代码实现大多数算术函数是有意义的。但是,在 System.Math 中没有与此函数或其他函数关联的 DllImport 调用。
核心问题是关于函数如何在 native 代码中实现,但我也想知道它位于哪个 native Dll 中。另外,为什么没有 DllImport?那是因为编译将其剥离了吗?
最佳答案
查看 Math.cs,您会注意到 Atan2 是直接作为内部调用实现的。
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern double Atan2(double y, double x);
这基本上告诉 .NET 调用底层 C++ 函数。
更多信息请访问: Is it possible to link a method marked with MethodImplOptions.InternalCall to its implementation?
下载地址: http://www.microsoft.com/en-us/download/details.aspx?id=4917
来自 comfloat.cpp:
/*=====================================Atan2=====================================
**
==============================================================================*/
FCIMPL2_VV(double, COMDouble::Atan2, double x, double y)
WRAPPER_CONTRACT;
STATIC_CONTRACT_SO_TOLERANT;
// the intrinsic for Atan2 does not produce Nan for Atan2(+-inf,+-inf)
if (IS_DBL_INFINITY(x) && IS_DBL_INFINITY(y)) {
return(x / y); // create a NaN
}
return (double) atan2(x, y);
FCIMPLEND
关于c# - Atan2 如何在 .NET 中实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17312195/
我是一名优秀的程序员,十分优秀!