[Mono-dev] System.Math implementation

Miguel de Icaza miguel at ximian.com
Mon Mar 20 17:44:55 EST 2006


Hello,
 
> 1. In the folder /mono/mcs/class/corlib/System there is a file
> Math.cs. Some functions in this class (eg. Sin, Cos, etc) are
> implemented in C. For example, the Sin function is declared as 
>  
>  [MethodImplAttribute (MethodImplOptions.InternalCall)]
>  public extern static double Sin (double x);
>  
> I tried to find the C implementation for the Sin function above. It
> looks like that it is implemented in /mono/mono/metadata/sysmath.c
> (see line 70). When I modify this function (eg. return (2.0 * sin
> (x)), why do I still get the same output? Why don't I get 2 * sin (x)?
> 
> If sysmath.c does not contain the implementaton, where is the
> Math.Sin() implemented?
> I really want to know how this works.

In some platforms Mono is able to replace the call into the C code with
direct floating point instructions.     In this particular case, am
assuming that you are using Mono on x86, the code is handled in:

	mono/mini/mini-x86.c

Look for `mono_arch_get_inst_for_method'

> 2. I know that the C# is written in C#. However, I believe that the
> very basic functionality of that C# co mpiler is implemented in C (am
> I right?). If yes, where can I find that C implementation?

The compiler is completely written in C#.  

The C# compiler lives in mcs/mcs
The C# compiler uses the class libraries in mcs/class
The class libraries sometimes use unmanaged code, that is in mono/

Miguel




More information about the Mono-devel-list mailing list