Commit 6a29a67d authored by Morten Welinder's avatar Morten Welinder

Complex: add a direct-value interface.

This makes for *much* more readable code.
parent 0b129f91
2016-02-12 Morten Welinder <>
* src/complex.h: Add a direct-value interface.
* src/ssconvert.c (run_solver): Also create solver reports as
indicated in options.
This diff is collapsed.
......@@ -84,12 +84,6 @@ gsl_complex_inverse (gnm_complex const *a, gnm_complex *res)
gnm_complex_init (res, (GSL_REAL (a) * s) * s, -(GSL_IMAG (a) * s) * s);
gsl_complex_negative (gnm_complex const *a, gnm_complex *res)
gnm_complex_init (res, -GSL_REAL (a), -GSL_IMAG (a));
* Inverse Complex Trigonometric Functions
......@@ -2,7 +2,6 @@
#define __GSL_COMPLEX_H__
void gsl_complex_inverse (gnm_complex const *a, gnm_complex *res);
void gsl_complex_negative (gnm_complex const *a, gnm_complex *res);
void gsl_complex_arcsin (gnm_complex const *a, gnm_complex *res);
void gsl_complex_arccos (gnm_complex const *a, gnm_complex *res);
void gsl_complex_arctan (gnm_complex const *a, gnm_complex *res);
......@@ -22,4 +21,32 @@ void gsl_complex_arcsech (gnm_complex const *a, gnm_complex *res);
void gsl_complex_arccsch (gnm_complex const *a, gnm_complex *res);
void gsl_complex_arccoth (gnm_complex const *a, gnm_complex *res);
static inline gnm_complex
gnm_complex_f1r_ (void (*f) (gnm_complex const *, gnm_complex *),
gnm_complex a1)
gnm_complex res;
f (&a1, &res);
return res;
#define GNM_CARCSIN(c1) (gnm_complex_f1r_ (gsl_complex_arcsin, (c1)))
#define GNM_CARCCOS(c1) (gnm_complex_f1r_ (gsl_complex_arccos, (c1)))
#define GNM_CARCTAN(c1) (gnm_complex_f1r_ (gsl_complex_arctan, (c1)))
#define GNM_CARCSEC(c1) (gnm_complex_f1r_ (gsl_complex_arcsec, (c1)))
#define GNM_CARCCSC(c1) (gnm_complex_f1r_ (gsl_complex_arccsc, (c1)))
#define GNM_CARCCOT(c1) (gnm_complex_f1r_ (gsl_complex_arccot, (c1)))
#define GNM_CSINH(c1) (gnm_complex_f1r_ (gsl_complex_sinh, (c1)))
#define GNM_CCOSH(c1) (gnm_complex_f1r_ (gsl_complex_cosh, (c1)))
#define GNM_CTANH(c1) (gnm_complex_f1r_ (gsl_complex_tanh, (c1)))
#define GNM_CSECH(c1) (gnm_complex_f1r_ (gsl_complex_sech, (c1)))
#define GNM_CCSCH(c1) (gnm_complex_f1r_ (gsl_complex_csch, (c1)))
#define GNM_CCOTH(c1) (gnm_complex_f1r_ (gsl_complex_coth, (c1)))
#define GNM_CARCSINH(c1) (gnm_complex_f1r_ (gsl_complex_arcsinh, (c1)))
#define GNM_CARCCOSH(c1) (gnm_complex_f1r_ (gsl_complex_arccosh, (c1)))
#define GNM_CARCTANH(c1) (gnm_complex_f1r_ (gsl_complex_arctanh, (c1)))
#define GNM_CARCSECH(c1) (gnm_complex_f1r_ (gsl_complex_arcsech, (c1)))
#define GNM_CARCCSCH(c1) (gnm_complex_f1r_ (gsl_complex_arccsch, (c1)))
#define GNM_CARCCOTH(c1) (gnm_complex_f1r_ (gsl_complex_arccoth, (c1)))
......@@ -68,6 +68,65 @@ int gnm_complex_from_string (gnm_complex *dst, char const *src, char *imunit);
int gnm_complex_invalid_p (gnm_complex const *src);
/* ------------------------------------------------------------------------- */
// Value interface
static inline gnm_complex
gnm_complex_f1_ (void (*f) (gnm_complex *, gnm_complex const *),
gnm_complex a1)
gnm_complex res;
f (&res, &a1);
return res;
static inline gnm_complex
gnm_complex_f2_ (void (*f) (gnm_complex *, gnm_complex const *, gnm_complex const *),
gnm_complex a1, gnm_complex a2)
gnm_complex res;
f (&res, &a1, &a2);
return res;
#define GNM_CRE(c) (+(c).re)
#define GNM_CIM(c) (+(c).re)
static inline gnm_complex GNM_CMAKE (gnm_float re, gnm_float im)
gnm_complex res; = re; = im;
return res;
#define GNM_CREAL(r) (GNM_CMAKE((r),0))
static inline gnm_float GNM_CARG (gnm_complex c) { return gnm_complex_angle (&c); }
static inline gnm_float GNM_CARGPI (gnm_complex c) { return gnm_complex_angle_pi (&c); }
static inline gnm_float GNM_CABS (gnm_complex c) { return gnm_complex_mod (&c); }
#define GNM_CADD(c1,c2) (gnm_complex_f2_ (gnm_complex_add, (c1), (c2)))
#define GNM_CSUB(c1,c2) (gnm_complex_f2_ (gnm_complex_sub, (c1), (c2)))
#define GNM_CMUL(c1,c2) (gnm_complex_f2_ (gnm_complex_mul, (c1), (c2)))
#define GNM_CDIV(c1,c2) (gnm_complex_f2_ (gnm_complex_div, (c1), (c2)))
#define GNM_CPOW(c1,c2) (gnm_complex_f2_ (gnm_complex_pow, (c1), (c2)))
#define GNM_CCONJ(c1) (gnm_complex_f1_ (gnm_complex_conj, (c1)))
#define GNM_CSQRT(c1) (gnm_complex_f1_ (gnm_complex_sqrt, (c1)))
#define GNM_CEXP(c1) (gnm_complex_f1_ (gnm_complex_exp, (c1)))
#define GNM_CLN(c1) (gnm_complex_f1_ (gnm_complex_ln, (c1)))
#define GNM_CSIN(c1) (gnm_complex_f1_ (gnm_complex_sin, (c1)))
#define GNM_CCOS(c1) (gnm_complex_f1_ (gnm_complex_cos, (c1)))
#define GNM_CTAN(c1) (gnm_complex_f1_ (gnm_complex_tan, (c1)))
#define GNM_CINV(c1) (GNM_CDIV (GNM_CREAL (1), (c1)))
static inline gnm_complex GNM_CNEG(gnm_complex c)
return GNM_CMAKE (,;
static inline gnm_complex GNM_CSCALE(gnm_complex c, gnm_float s)
return GNM_CMAKE ( * s, * s);
/* ------------------------------------------------------------------------- */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment