Revert some changes which don't have proper dependencies.
[mono-project.git] / mono / utils / mono-complex.h
blobe817ac5e472e05c8976055a6d5ee7ab6b4964436
1 /**
2 * \file
3 * C99 Complex math cross-platform support code
5 * Author:
6 * Joao Matos (joao.matos@xamarin.com)
8 * Copyright 2015 Xamarin, Inc (http://www.xamarin.com)
9 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
12 #include <config.h>
13 #include <glib.h>
14 #define _USE_MATH_DEFINES // needed by MSVC to define math constants
15 #include <math.h>
17 typedef struct double_complex {
18 double real;
19 double imag;
20 } double_complex;
22 #define mono_creal(c) ((c).real)
23 #define mono_cimag(c) ((c).imag)
25 static inline
26 double_complex mono_double_complex_make(gdouble re, gdouble im)
28 double_complex const a = { re, im };
29 return a;
32 static inline
33 double_complex mono_double_complex_scalar_div(double_complex c, gdouble s)
35 return mono_double_complex_make (mono_creal (c) / s, mono_cimag (c) / s);
38 static inline
39 double_complex mono_double_complex_scalar_mul(double_complex c, gdouble s)
41 return mono_double_complex_make (mono_creal (c) * s, mono_cimag (c) * s);
44 static inline
45 double_complex mono_double_complex_div(double_complex left, double_complex right)
47 double denom = mono_creal (right) * mono_creal (right) + mono_cimag (right) * mono_cimag (right);
49 return mono_double_complex_make(
50 (mono_creal (left) * mono_creal (right) + mono_cimag (left) * mono_cimag (right)) / denom,
51 (-mono_creal (left) * mono_cimag (right) + mono_cimag (left) * mono_creal (right)) / denom);
54 static inline
55 double_complex mono_double_complex_sub(double_complex left, double_complex right)
57 return mono_double_complex_make (mono_creal (left) - mono_creal (right), mono_cimag (left)
58 - mono_cimag (right));
61 #include "../../support/libm/complex.c"