Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

clr

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

Is there anything I am missing here?

like image 788
kiss my armpit Avatar asked Aug 15 '14 14:08

kiss my armpit


People also ask

What is math sin in Javascript?

The Math. sin() method in Javascript is used to return the sine of a number. The Math. sin() method returns a numeric value between -1 and 1, which represents the sine of the angle given in radians. The sin() is a static method of Math, therefore, it is always used as Math.


3 Answers

The signature of the method is:

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

The extern in the method means it is defined elsewhere. In this case, it will be implemented directly in the CLR (probably written in C or Assembly) which means there is no .NET implementation available.

like image 102
Patrick Hofman Avatar answered Sep 18 '22 20:09

Patrick Hofman


You can't thought the .NET Framework source - it's an extern function, meaning it's implemented in a lower-level library (probably the CLR itself, but I'm not certain).

You might try the Shared Source CLI

like image 32
D Stanley Avatar answered Sep 20 '22 20:09

D Stanley


No you cannot see the source code of the sin function as its an extern function and embedded inside CLR. sine is implemented in microcode inside microprocessors, so this makes it really hard to check the implementation of the same as it may differ from platform to platform.

The extern modifier is used to declare a method that is implemented externally

And the sin function is declared as

public static extern double Sin(double x);

So it is not possible to see the source code for the sin function

I am not sure if this can be of any help but you may check the C version of the sin fucntion and also check sin function implementation.

like image 42
Rahul Tripathi Avatar answered Sep 17 '22 20:09

Rahul Tripathi