[runtime] Rename most System.Reflection.MonoX classes to RuntimeX for consistency...
[mono-project.git] / mono / metadata / sysmath.c
blob7e250fbaae2d078827715802a55c51577bb6d611
1 /**
2 * \file
3 * these are based on bob smith's csharp routines
5 * Author:
6 * Mono Project (http://www.mono-project.com)
7 * Ludovic Henry (ludovic@xamarin.com)
9 * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
10 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
11 * Copyright 2015 Xamarin, Inc (https://www.xamarin.com)
12 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
16 // Copyright (c) Microsoft. All rights reserved.
17 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
19 // Files:
20 // - src/classlibnative/float/floatnative.cpp
21 // - src/pal/src/cruntime/floatnative.cpp
23 // Ported from C++ to C and adjusted to Mono runtime
25 #define __USE_ISOC99
27 #include <math.h>
29 #include "number-ms.h"
30 #include "utils/mono-compiler.h"
31 #include "icalls.h"
32 #include "icall-decl.h"
34 gdouble
35 ves_icall_System_Math_Floor (gdouble x)
37 return floor(x);
40 gdouble
41 ves_icall_System_Math_Round (gdouble x)
43 gdouble floor_tmp;
45 /* If the number has no fractional part do nothing This shortcut is necessary
46 * to workaround precision loss in borderline cases on some platforms */
47 if (x == (gdouble)(gint64) x)
48 return x;
50 floor_tmp = floor (x + 0.5);
52 if ((x == (floor (x) + 0.5)) && (fmod (floor_tmp, 2.0) != 0)) {
53 floor_tmp -= 1.0;
56 return copysign (floor_tmp, x);
59 gdouble
60 ves_icall_System_Math_FMod (gdouble x, gdouble y)
62 return fmod (x, y);
65 gdouble
66 ves_icall_System_Math_ModF (gdouble x, gdouble *d)
68 return modf (x, d);
71 gdouble
72 ves_icall_System_Math_Sin (gdouble x)
74 return sin (x);
77 gdouble
78 ves_icall_System_Math_Cos (gdouble x)
80 return cos (x);
83 gdouble
84 ves_icall_System_Math_Cbrt (gdouble x)
86 return cbrt (x);
89 gdouble
90 ves_icall_System_Math_Tan (gdouble x)
92 return tan (x);
95 gdouble
96 ves_icall_System_Math_Sinh (gdouble x)
98 return sinh (x);
101 gdouble
102 ves_icall_System_Math_Cosh (gdouble x)
104 return cosh (x);
107 gdouble
108 ves_icall_System_Math_Tanh (gdouble x)
110 return tanh (x);
113 gdouble
114 ves_icall_System_Math_Acos (gdouble x)
116 return acos (x);
119 gdouble
120 ves_icall_System_Math_Acosh (gdouble x)
122 return acosh (x);
125 gdouble
126 ves_icall_System_Math_Asin (gdouble x)
128 return asin (x);
131 gdouble
132 ves_icall_System_Math_Asinh (gdouble x)
134 return asinh (x);
137 gdouble
138 ves_icall_System_Math_Atan (gdouble x)
140 return atan (x);
143 gdouble
144 ves_icall_System_Math_Atan2 (gdouble y, gdouble x)
146 return atan2 (y, x);
149 gdouble
150 ves_icall_System_Math_Atanh (gdouble x)
152 return atanh (x);
155 gdouble
156 ves_icall_System_Math_Exp (gdouble x)
158 return exp (x);
161 gdouble
162 ves_icall_System_Math_Log (gdouble x)
164 return log (x);
167 gdouble
168 ves_icall_System_Math_Log10 (gdouble x)
170 return log10 (x);
173 gdouble
174 ves_icall_System_Math_Pow (gdouble x, gdouble y)
176 return pow (x, y);
179 gdouble
180 ves_icall_System_Math_Sqrt (gdouble x)
182 return sqrt (x);
185 gdouble
186 ves_icall_System_Math_Abs_double (gdouble v)
188 return fabs (v);
191 float
192 ves_icall_System_Math_Abs_single (float v)
194 return fabsf (v);
197 gdouble
198 ves_icall_System_Math_Ceiling (gdouble v)
200 return ceil (v);
203 float
204 ves_icall_System_MathF_Acos (float x)
206 return acosf (x);
209 float
210 ves_icall_System_MathF_Acosh (float x)
212 return acoshf (x);
215 float
216 ves_icall_System_MathF_Asin (float x)
218 return asinf (x);
221 float
222 ves_icall_System_MathF_Asinh (float x)
224 return asinhf (x);
227 float
228 ves_icall_System_MathF_Atan (float x)
230 return atan (x);
233 float
234 ves_icall_System_MathF_Atan2 (float x, float y)
236 return atan2f (x, y);
239 float
240 ves_icall_System_MathF_Atanh (float x)
242 return atanhf (x);
245 float
246 ves_icall_System_MathF_Cbrt (float x)
248 return cbrtf (x);
251 float
252 ves_icall_System_MathF_Ceiling (float x)
254 return ceilf(x);
257 float
258 ves_icall_System_MathF_Cos (float x)
260 return cosf (x);
263 float
264 ves_icall_System_MathF_Cosh (float x)
266 return coshf (x);
269 float
270 ves_icall_System_MathF_Exp (float x)
272 return expf (x);
275 float
276 ves_icall_System_MathF_Floor (float x)
278 return floorf (x);
281 float
282 ves_icall_System_MathF_Log (float x)
284 return logf (x);
287 float
288 ves_icall_System_MathF_Log10 (float x)
290 return log10f (x);
293 float
294 ves_icall_System_MathF_Pow (float x, float y)
296 return powf (x, y);
299 float
300 ves_icall_System_MathF_Sin (float x)
302 return sinf (x);
305 float
306 ves_icall_System_MathF_Sinh (float x)
308 return sinh (x);
311 float
312 ves_icall_System_MathF_Sqrt (float x)
314 return sqrtf (x);
317 float
318 ves_icall_System_MathF_Tan (float x)
320 return tanf (x);
323 float
324 ves_icall_System_MathF_Tanh (float x)
326 return tanh (x);
329 float
330 ves_icall_System_MathF_FMod (float x, float y)
332 return fmodf (x, y);
335 float
336 ves_icall_System_MathF_ModF (float x, float *d)
338 return modff (x, d);