gpt4 book ai didi

c# - Atan2 如何在 .NET 中实现?

转载 作者:太空狗 更新时间:2023-10-29 23:46:27 24 4
gpt4 key购买 nike

我在反射器中寻找 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com