FastPolyEval  1.0
Fast Evaluation of Real and Complex Polynomials
comp.h
Go to the documentation of this file.
1 //
2 // comp.h
3 //
4 // Authors: Nicolae Mihalache & François Vigneron
5 //
6 // This software is released under BSD licence, with an attribution clause (see Licence file).
7 // Please cite the reference below if you use or distribute this software.
8 //
9 // • [1] R. Anton, N. Mihalache & F. Vigneron. Fast evaluation of real and complex polynomials. 2022.
10 // https://hal.archives-ouvertes.fr/hal-03820369
11 //
12 // Copyright 2022 Univ. Paris-Est Créteil & Univ. de Reims Champagne-Ardenne.
13 //
14 
20 #ifndef comp_h
21 #define comp_h
22 
23 #include <mpfr.h>
24 
25 #include "ntypes.h"
26 
27 // MARK: data types
28 
31 typedef struct {
32  mpfr_t x;
33  mpfr_t y;
34 } comp_struct;
35 
39 typedef comp_struct comp[1];
40 
43 
44 // MARK: macros & functions prototypes
45 
47 #define comp_init(d, prec) mpfr_init2((d)->x, prec); \
48  mpfr_init2((d)->y, prec);
49 
51 #define comp_initz(d, prec) mpfr_init2((d)->x, prec); \
52  mpfr_init2((d)->y, prec); \
53  mpfr_set_zero((d)->x, 1); \
54  mpfr_set_zero((d)->y, 1);
55 
57 #define comp_clear(d) mpfr_clear((d)->x); \
58  mpfr_clear((d)->y);
59 
61 #define comp_zero(d) (mpfr_zero_p((d)->x) && mpfr_zero_p((d)->y))
62 
64 #define comp_add(d, a, b) mpfr_add((d)->x, (a)->x, (b)->x, MPFR_RNDN); \
65  mpfr_add((d)->y, (a)->y, (b)->y, MPFR_RNDN);
66 
68 #define comp_set(d, a) mpfr_set((d)->x, (a)->x, MPFR_RNDN); \
69  mpfr_set((d)->y, (a)->y, MPFR_RNDN);
70 
72 #define comp_setr(d, a) mpfr_set((d)->x, (a), MPFR_RNDN); \
73  mpfr_set_zero((d)->y, 1);
74 
76 #define comp_neg(d, a) mpfr_neg((d)->x, (a)->x, MPFR_RNDN); \
77  mpfr_neg((d)->y, (a)->y, MPFR_RNDN);
78 
80 #define comp_addr(d, a, r) mpfr_add((d)->x, (a)->x, (r), MPFR_RNDN); \
81  mpfr_set((d)->y, (a)->y, MPFR_RNDN);
82 
84 #define comp_amu(d, a, r, buf) mpfr_mul_ui((buf), (a)->x, (r), MPFR_RNDN); \
85  mpfr_add((d)->x, (d)->x, (buf), MPFR_RNDN); \
86  mpfr_mul_ui((buf), (a)->y, (r), MPFR_RNDN); \
87  mpfr_add((d)->y, (d)->y, (buf), MPFR_RNDN);
88 
90 #define comp_sub(d, a, b) mpfr_sub((d)->x, (a)->x, (b)->x, MPFR_RNDN); \
91  mpfr_sub((d)->y, (a)->y, (b)->y, MPFR_RNDN);
92 
94 #define comp_subr(d, a, r) mpfr_sub((d)->x, (a)->x, (r), MPFR_RNDN); \
95  mpfr_set((d)->y, (a)->y, MPFR_RNDN);
96 
98 #define comp_mul(d, a, b, buf1, buf2) mpfr_mul((buf1), (a)->x, (b)->x, MPFR_RNDN); \
99  mpfr_mul((buf2), (a)->y, (b)->y, MPFR_RNDN); \
100  mpfr_sub((buf1), (buf1), (buf2), MPFR_RNDN); \
101  mpfr_mul((buf2), (a)->x, (b)->y, MPFR_RNDN); \
102  mpfr_mul((d)->y, (a)->y, (b)->x, MPFR_RNDN); \
103  mpfr_add((d)->y, (d)->y, (buf2), MPFR_RNDN); \
104  mpfr_set((d)->x, (buf1), MPFR_RNDN);
105 
107 #define comp_div(d, a, b, b1, b2, b3) mpfr_sqr((b3), (b)->x, MPFR_RNDN); \
108  mpfr_sqr((b2), (b)->y, MPFR_RNDN); \
109  mpfr_add((b3), (b3), (b2), MPFR_RNDN); \
110  mpfr_mul((b1), (a)->x, (b)->x, MPFR_RNDN); \
111  mpfr_mul((b2), (a)->y, (b)->y, MPFR_RNDN); \
112  mpfr_add((b1), (b1), (b2), MPFR_RNDN); \
113  mpfr_mul((b2), (a)->x, (b)->y, MPFR_RNDN); \
114  mpfr_mul((d)->y, (a)->y, (b)->x, MPFR_RNDN); \
115  mpfr_sub((d)->y, (d)->y, (b2), MPFR_RNDN); \
116  mpfr_div((d)->y, (d)->y, (b3), MPFR_RNDN); \
117  mpfr_div((d)->x, (b1), (b3), MPFR_RNDN);
118 
120 #define comp_mod(m, a) mpfr_hypot((m), (a)->x, (a)->y, MPFR_RNDN);
121 
123 #define comp_mulr(d, a, r) mpfr_mul((d)->x, (a)->x, (r), MPFR_RNDN); \
124  mpfr_mul((d)->y, (a)->y, (r), MPFR_RNDN);
125 
127 #define comp_muli(d, a, i) mpfr_mul_si((d)->x, (a)->x, (i), MPFR_RNDN); \
128  mpfr_mul_si((d)->y, (a)->y, (i), MPFR_RNDN);
129 
131 #define comp_mulu(d, a, i) mpfr_mul_ui((d)->x, (a)->x, (i), MPFR_RNDN); \
132  mpfr_mul_ui((d)->y, (a)->y, (i), MPFR_RNDN);
133 
135 #define comp_sqr(d, a, buf) mpfr_sqr((buf), (a)->y, MPFR_RNDN); \
136  mpfr_mul((d)->y, (a)->x, (a)->y, MPFR_RNDN); \
137  mpfr_mul_2si((d)->y, (d)->y, 1, MPFR_RNDN); \
138  mpfr_sqr((d)->x, (a)->x, MPFR_RNDN); \
139  mpfr_sub((d)->x, (d)->x, (buf), MPFR_RNDN);
140 
147 
153 real_t real_log2(mpfr_t x);
154 
163 
171 real_t mpfr_s(mpfr_t x);
172 
173 #endif /* comp_h */
real_t comp_log2(comp z)
Computes the base 2 log of |z|.
real_t real_log2(mpfr_t x)
Computes the base 2 log of |x|.
comp_struct * comp_ptr
Convenience pointer to comp_struct.
Definition: comp.h:42
real_t mpfr_s(mpfr_t x)
Computes s(x).
real_t comp_s(comp z)
Computes s(z).
comp_struct comp[1]
Practical wrapper for comp_struct.
Definition: comp.h:39
Definition of basic types.
double real_t
The machine number type to use for polynomial analysis and preconditionning.
Definition: ntypes.h:163
Multi-precision floating point complex numbers.
Definition: comp.h:31
mpfr_t x
the real part of the complex number
Definition: comp.h:32
mpfr_t y
the imaginary part of the complex number
Definition: comp.h:33