I was looking for the .NET implementation of Atan2 in a reflector and found the following line:
public static extern double Atan2(double y, double x);
That is not surprising since it makes sense for most arithmetic functions to be implemented in native code. However, there was no DllImport call associated with this or other functions in System.Math.
The core question is about how the function implemented in native code but I would also like to know which native Dll it resides in. Also, why is there no DllImport? Is that because compilation strips it away?
Looking at Math.cs you'll notice that Atan2 is implemented directly as an internal call.
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern double Atan2(double y, double x);
This basically tells .NET to call an underlying C++ function.
More information at: Is it possible to link a method marked with MethodImplOptions.InternalCall to its implementation?
Download at: http://www.microsoft.com/en-us/download/details.aspx?id=4917
from 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With