[tools] Add nuget-hash-extractor tool to help produce the runtime ignored assemblies...
[mono-project.git] / mono / utils / mono-complex.h
blobaf13bf62b982d00032f425312560f2312d5a505a
1 /*
2 * mono-complex.h: C99 Complex math cross-platform support code
4 * Author:
5 * Joao Matos (joao.matos@xamarin.com)
7 * Copyright 2015 Xamarin, Inc (http://www.xamarin.com)
8 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
9 */
11 #include <config.h>
12 #include <glib.h>
14 #if !defined (HAVE_COMPLEX_H)
15 #include <../../support/libm/complex.h>
16 #else
17 #include <complex.h>
18 #endif
20 #define _USE_MATH_DEFINES // needed by MSVC to define math constants
21 #include <math.h>
23 #ifdef _MSC_VER
25 #define double_complex _C_double_complex
27 static inline
28 double_complex mono_double_complex_make(gdouble re, gdouble im)
30 return _Cbuild (re, im);
33 static inline
34 double_complex mono_double_complex_scalar_div(double_complex c, gdouble s)
36 return mono_double_complex_make(creal(c) / s, cimag(c) / s);
39 static inline
40 double_complex mono_double_complex_scalar_mul(double_complex c, gdouble s)
42 return mono_double_complex_make(creal(c) * s, cimag(c) * s);
45 static inline
46 double_complex mono_double_complex_div(double_complex left, double_complex right)
48 double denom = creal(right) * creal(right) + cimag(right) * cimag(right);
50 return mono_double_complex_make(
51 (creal(left) * creal(right) + cimag(left) * cimag(right)) / denom,
52 (-creal(left) * cimag(right) + cimag(left) * creal(right)) / denom);
55 static inline
56 double_complex mono_double_complex_sub(double_complex left, double_complex right)
58 return mono_double_complex_make(creal(left) - creal(right), cimag(left)
59 - cimag(right));
62 #else
64 #define double_complex double complex
66 static inline
67 double_complex mono_double_complex_make(gdouble re, gdouble im)
69 return re + im * I;
72 static inline
73 double_complex mono_double_complex_scalar_div(double_complex c, gdouble s)
75 return c / s;
78 static inline
79 double_complex mono_double_complex_scalar_mul(double_complex c, gdouble s)
81 return c * s;
84 static inline
85 double_complex mono_double_complex_div(double_complex left, double_complex right)
87 return left / right;
90 static inline
91 double_complex mono_double_complex_sub(double_complex left, double_complex right)
93 return left - right;
96 #endif