How can I see the source code for System.Math.Sin?

In this link we can see the source code of the System.Math class. But I can not find the source code of how the sine is determined.

Is there anything I don't see here?

+6
source share
6 answers

Method Signature:

  [System.Security.SecuritySafeCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern double Sin(double a); 

extern in a method means that it is defined elsewhere. In this case, it will be implemented directly in the CLR (possibly written in C or Assembly), which means that the .NET implementation is not available.

+9
source

You cannot think that the source of the .NET Framework is an extern function, that is, it is implemented in a lower-level library (probably the CLR itself, but I'm not sure).

You can try the shared CLI

+5
source

No, you cannot see the source code of the sin function as an extern function and built-in inside the CLR. the sine is implemented in microcode inside the microprocessors, which makes it very difficult to verify the implementation, since it can differ from platform to platform.

The extern modifier is used to declare a method that is executed externally.

And the sin function is declared as

 public static extern double Sin(double x); 

Thus, it is not possible to see the source code of the sin function

I'm not sure if this can help, but you can check the C version of the sin fucntion version as well as check the implementation of the sin function.

+1
source

If you want to see the restored source code, you can try Telerik JustDecompile:

http://www.telerik.com/products/decompiler.aspx

Used when viewing the source code of a library when it is not available. It generates a clear IMO output.

0
source

If you want only one implementation, you can study the libmath math library of the basic bc calculator, the gnu version can be read at http://code.metager.de/source/xref/gnu/bc/1.06/bc/libmath.b

It normalizes the wrt argument. pi, and then uses the Taylor series sin.

0
source

According to Rahul Tripati, if C # Sin is C Sin, it uses a 13 degree polynomial. http://www.netlib.org/fdlibm/k_sin.c

Algorithm /* __kernel_sin( x, y, iy) * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854 * Input x is assumed to be bounded by ~pi/4 in magnitude. * Input y is the tail of x. * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). * * Algorithm * 1. Since sin(-x) = -sin(x), we need only to consider positive x. * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0. * 3. sin(x) is approximated by a polynomial of degree 13 on * [0,pi/4] * 3 13 * sin(x) ~ x + S1*x + ... + S6*x * where *
* |sin(x) 2 4 6 8 10 12 | -58 * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 * | x | * * 4. sin(x+y) = sin(x) + sin'(x')*y * ~ sin(x) + (1-x*x/2)*y * For better accuracy, let * 3 2 2 2 2 * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) * then 3 2 * sin(x) = x + (S1*x + (x *(ry/2)+y)) */

-1
source

Source: https://habr.com/ru/post/973867/


All Articles