Introspection: fix problems with boxed type.
[gnumeric.git] / src / complex.h
blobf509ad49171fdafa68f56e5c92905895f27c2e8a
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 #ifndef _GNM_COMPLEX_H_
3 # define _GNM_COMPLEX_H_
5 #include "numbers.h"
6 #include <goffice/goffice.h>
7 #include <math.h>
9 G_BEGIN_DECLS
11 #ifdef GNM_WITH_LONG_DOUBLE
12 #define gnm_complex GOComplexl
13 #define gnm_complex_init go_complex_initl
14 #define gnm_complex_add go_complex_addl
15 #define gnm_complex_sub go_complex_subl
16 #define gnm_complex_mul go_complex_mull
17 #define gnm_complex_div go_complex_divl
18 #define gnm_complex_mod go_complex_modl
19 #define gnm_complex_angle go_complex_anglel
20 #define gnm_complex_angle_pi go_complex_angle_pil
21 #define gnm_complex_real go_complex_reall
22 #define gnm_complex_real_p go_complex_real_pl
23 #define gnm_complex_zero_p go_complex_zero_pl
24 #define gnm_complex_conj go_complex_conjl
25 #define gnm_complex_exp go_complex_expl
26 #define gnm_complex_ln go_complex_lnl
27 #define gnm_complex_sqrt go_complex_sqrtl
28 #define gnm_complex_sin go_complex_sinl
29 #define gnm_complex_cos go_complex_cosl
30 #define gnm_complex_tan go_complex_tanl
31 #define gnm_complex_pow go_complex_powl
32 #define gnm_complex_powx go_complex_powxl
33 #define gnm_complex_scale_real go_complex_scale_reall
34 #define gnm_complex_to_polar go_complex_to_polarl
35 #define gnm_complex_from_polar go_complex_from_polarl
36 #define gnm_complex_from_polar_pi go_complex_from_polar_pil
37 #else
38 #define gnm_complex GOComplex
39 #define gnm_complex_init go_complex_init
40 #define gnm_complex_add go_complex_add
41 #define gnm_complex_sub go_complex_sub
42 #define gnm_complex_mul go_complex_mul
43 #define gnm_complex_div go_complex_div
44 #define gnm_complex_mod go_complex_mod
45 #define gnm_complex_angle go_complex_angle
46 #define gnm_complex_angle_pi go_complex_angle_pi
47 #define gnm_complex_real go_complex_real
48 #define gnm_complex_real_p go_complex_real_p
49 #define gnm_complex_zero_p go_complex_zero_p
50 #define gnm_complex_conj go_complex_conj
51 #define gnm_complex_exp go_complex_exp
52 #define gnm_complex_ln go_complex_ln
53 #define gnm_complex_sqrt go_complex_sqrt
54 #define gnm_complex_sin go_complex_sin
55 #define gnm_complex_cos go_complex_cos
56 #define gnm_complex_tan go_complex_tan
57 #define gnm_complex_pow go_complex_pow
58 #define gnm_complex_powx go_complex_powx
59 #define gnm_complex_scale_real go_complex_scale_real
60 #define gnm_complex_to_polar go_complex_to_polar
61 #define gnm_complex_from_polar go_complex_from_polar
62 #define gnm_complex_from_polar_pi go_complex_from_polar_pi
63 #endif
65 /* ------------------------------------------------------------------------- */
67 char *gnm_complex_to_string (gnm_complex const *src, char imunit);
69 int gnm_complex_from_string (gnm_complex *dst, char const *src, char *imunit);
71 int gnm_complex_invalid_p (gnm_complex const *src);
73 /* ------------------------------------------------------------------------- */
74 // Value interface
76 static inline gnm_complex
77 gnm_complex_f1_ (void (*f) (gnm_complex *, gnm_complex const *),
78 gnm_complex a1)
80 gnm_complex res;
81 f (&res, &a1);
82 return res;
85 static inline gnm_complex
86 gnm_complex_f2_ (void (*f) (gnm_complex *, gnm_complex const *, gnm_complex const *),
87 gnm_complex a1, gnm_complex a2)
89 gnm_complex res;
90 f (&res, &a1, &a2);
91 return res;
94 #define GNM_CRE(c) (+(c).re)
95 #define GNM_CIM(c) (+(c).im)
96 static inline gnm_complex GNM_CMAKE (gnm_float re, gnm_float im)
98 gnm_complex res;
99 res.re = re;
100 res.im = im;
101 return res;
103 #define GNM_CREAL(r) (GNM_CMAKE((r),0))
104 #define GNM_CREALP(c) (GNM_CIM((c)) == 0)
105 #define GNM_CZEROP(c) (GNM_CEQ((c),GNM_C0))
106 #define GNM_C0 (GNM_CREAL (0))
107 #define GNM_C1 (GNM_CREAL (1))
108 #define GNM_CI (GNM_CMAKE (0, 1))
109 #define GNM_CNAN (GNM_CMAKE (gnm_nan, gnm_nan))
111 static inline gboolean GNM_CEQ(gnm_complex c1, gnm_complex c2)
113 return c1.re == c2.re && c1.im == c2.im;
116 static inline gnm_complex GNM_CPOLAR (gnm_float mod, gnm_float angle)
118 gnm_complex res;
119 gnm_complex_from_polar (&res, mod, angle);
120 return res;
122 static inline gnm_complex GNM_CPOLARPI (gnm_float mod, gnm_float angle)
124 gnm_complex res;
125 gnm_complex_from_polar_pi (&res, mod, angle);
126 return res;
128 static inline gnm_float GNM_CARG (gnm_complex c) { return gnm_complex_angle (&c); }
129 static inline gnm_float GNM_CARGPI (gnm_complex c) { return gnm_complex_angle_pi (&c); }
130 static inline gnm_float GNM_CABS (gnm_complex c) { return gnm_complex_mod (&c); }
132 #define GNM_CADD(c1,c2) (gnm_complex_f2_ (gnm_complex_add, (c1), (c2)))
133 #define GNM_CSUB(c1,c2) (gnm_complex_f2_ (gnm_complex_sub, (c1), (c2)))
134 #define GNM_CMUL(c1,c2) (gnm_complex_f2_ (gnm_complex_mul, (c1), (c2)))
135 #define GNM_CMUL3(c1,c2,c3) GNM_CMUL(GNM_CMUL(c1,c2),c3)
136 #define GNM_CMUL4(c1,c2,c3,c4) GNM_CMUL(GNM_CMUL(GNM_CMUL(c1,c2),c3),c4)
137 #define GNM_CDIV(c1,c2) (gnm_complex_f2_ (gnm_complex_div, (c1), (c2)))
138 #define GNM_CPOW(c1,c2) (gnm_complex_f2_ (gnm_complex_pow, (c1), (c2)))
139 static inline gnm_complex GNM_CPOWX(gnm_complex c1, gnm_complex c2, gnm_float *e)
141 gnm_complex res;
142 gnm_complex_powx (&res, e, &c1, &c2);
143 return res;
146 #define GNM_CCONJ(c1) (gnm_complex_f1_ (gnm_complex_conj, (c1)))
147 #define GNM_CSQRT(c1) (gnm_complex_f1_ (gnm_complex_sqrt, (c1)))
148 #define GNM_CEXP(c1) (gnm_complex_f1_ (gnm_complex_exp, (c1)))
149 #define GNM_CLN(c1) (gnm_complex_f1_ (gnm_complex_ln, (c1)))
150 #define GNM_CSIN(c1) (gnm_complex_f1_ (gnm_complex_sin, (c1)))
151 #define GNM_CCOS(c1) (gnm_complex_f1_ (gnm_complex_cos, (c1)))
152 #define GNM_CTAN(c1) (gnm_complex_f1_ (gnm_complex_tan, (c1)))
153 #define GNM_CINV(c1) (GNM_CDIV (GNM_C1, (c1)))
154 static inline gnm_complex GNM_CNEG(gnm_complex c)
156 return GNM_CMAKE (-c.re, -c.im);
159 static inline gnm_complex GNM_CSCALE(gnm_complex c, gnm_float s)
161 return GNM_CMAKE (c.re * s, c.im * s);
163 static inline gnm_complex GNM_CLDEXP(gnm_complex c, gnm_float e)
165 int ie = (int)CLAMP (e, G_MININT, G_MAXINT);
166 return GNM_CMAKE (gnm_ldexp (c.re, ie), gnm_ldexp (c.im, ie));
169 static inline gnm_complex GNM_CEXPPI(gnm_complex c)
171 return GNM_CPOLARPI (gnm_exp (c.re), c.im);
174 /* ------------------------------------------------------------------------- */
176 G_END_DECLS
178 #endif /* _GNM_COMPLEX_H_ */