3 * C99 Complex math cross-platform support code
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.
14 #define _USE_MATH_DEFINES // needed by MSVC to define math constants
17 typedef struct double_complex
{
22 #define mono_creal(c) ((c).real)
23 #define mono_cimag(c) ((c).imag)
26 double_complex
mono_double_complex_make(gdouble re
, gdouble im
)
28 double_complex
const a
= { re
, im
};
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
);
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
);
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
);
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"