Wed Sep 11 12:53:28 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / sysmath.c
1 /* math.c - these are based on bob smith's csharp routines */\r
2 \r
3 #define __USE_ISOC99\r
4 #include <math.h>\r
5 #include <mono/metadata/sysmath.h>\r
6 \r
7 #ifndef NAN\r
8 # if G_BYTE_ORDER == G_BIG_ENDIAN\r
9 #  define __nan_bytes           { 0x7f, 0xc0, 0, 0 }\r
10 # endif\r
11 # if G_BYTE_ORDER == G_LITTLE_ENDIAN\r
12 #  define __nan_bytes           { 0, 0, 0xc0, 0x7f }\r
13 # endif\r
14 \r
15 static union { unsigned char __c[4]; float __d; } __nan_union = { __nan_bytes };\r
16 # define NAN    (__nan_union.__d)\r
17 #endif\r
18 \r
19 #ifndef HUGE_VAL\r
20 #define __huge_val_t   union { unsigned char __c[8]; double __d; }\r
21 # if G_BYTE_ORDER == G_BIG_ENDIAN\r
22 #  define __HUGE_VAL_bytes       { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }\r
23 # endif\r
24 # if G_BYTE_ORDER == G_LITTLE_ENDIAN\r
25 #  define __HUGE_VAL_bytes       { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }\r
26 # endif\r
27 static __huge_val_t __huge_val = { __HUGE_VAL_bytes };\r
28 #  define HUGE_VAL      (__huge_val.__d)\r
29 #endif\r
30 \r
31 gdouble \r
32 ves_icall_System_Math_Sin (gdouble x)\r
33 {\r
34         return sin (x);\r
35 }\r
36 \r
37 gdouble \r
38 ves_icall_System_Math_Cos (gdouble x)\r
39 {\r
40         return cos (x);\r
41 }\r
42 \r
43 gdouble \r
44 ves_icall_System_Math_Tan (gdouble x)\r
45 {\r
46         return tan (x);\r
47 }\r
48 \r
49 gdouble \r
50 ves_icall_System_Math_Sinh (gdouble x)\r
51 {\r
52         return sinh (x);\r
53 }\r
54 \r
55 gdouble \r
56 ves_icall_System_Math_Cosh (gdouble x)\r
57 {\r
58         return cosh (x);\r
59 }\r
60 \r
61 gdouble \r
62 ves_icall_System_Math_Tanh (gdouble x)\r
63 {\r
64         return tanh (x);\r
65 }\r
66 \r
67 gdouble \r
68 ves_icall_System_Math_Acos (gdouble x)\r
69 {\r
70         if (x < -1 || x > 1)\r
71                 return NAN;\r
72 \r
73         return acos (x);\r
74 }\r
75 \r
76 gdouble \r
77 ves_icall_System_Math_Asin (gdouble x)\r
78 {\r
79         if (x < -1 || x > 1)\r
80                 return NAN;\r
81 \r
82         return asin (x);\r
83 }\r
84 \r
85 gdouble \r
86 ves_icall_System_Math_Atan (gdouble x)\r
87 {\r
88         return atan (x);\r
89 }\r
90 \r
91 gdouble \r
92 ves_icall_System_Math_Atan2 (gdouble y, gdouble x)\r
93 {\r
94         return atan2 (y, x);\r
95 }\r
96 \r
97 gdouble \r
98 ves_icall_System_Math_Exp (gdouble x)\r
99 {\r
100         return exp (x);\r
101 }\r
102 \r
103 gdouble \r
104 ves_icall_System_Math_Log (gdouble x)\r
105 {\r
106         if (x == 0)\r
107                 return -HUGE_VAL;\r
108         else if (x < 0)\r
109                 return NAN;\r
110 \r
111         return log (x);\r
112 }\r
113 \r
114 gdouble \r
115 ves_icall_System_Math_Log10 (gdouble x)\r
116 {\r
117         if (x == 0)\r
118                 return -HUGE_VAL;\r
119         else if (x < 0)\r
120                 return NAN;\r
121 \r
122         return log10 (x);\r
123 }\r
124 \r
125 gdouble \r
126 ves_icall_System_Math_Pow (gdouble x, gdouble y)\r
127 {\r
128         return pow (x, y);\r
129 }\r
130 \r
131 gdouble \r
132 ves_icall_System_Math_Sqrt (gdouble x)\r
133 {\r
134         if (x < 0)\r
135                 return NAN;\r
136 \r
137         return sqrt (x);\r
138 }\r