2 * mono-complex.h: C99 Complex math cross-platform support code
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.
14 #if !defined (HAVE_COMPLEX_H)
15 #include <../../support/libm/complex.h>
20 #define _USE_MATH_DEFINES // needed by MSVC to define math constants
25 #define double_complex _C_double_complex
28 double_complex mono_double_complex_make(gdouble re, gdouble im)
30 return _Cbuild (re, im);
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);
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);
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);
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)
64 #define double_complex double complex
67 double_complex mono_double_complex_make(gdouble re, gdouble im)
73 double_complex mono_double_complex_scalar_div(double_complex c, gdouble s)
79 double_complex mono_double_complex_scalar_mul(double_complex c, gdouble s)
85 double_complex mono_double_complex_div(double_complex left, double_complex right)
91 double_complex mono_double_complex_sub(double_complex left, double_complex right)