FastPolyEval  1.0
Fast Evaluation of Real and Complex Polynomials
compf.h
Go to the documentation of this file.
1 //
2 // compf.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 compf_h
21 #define compf_h
22 
23 #include "ntypes.h"
24 
25 // MARK: data types
26 
29 typedef struct {
32 } compf_struct;
33 
43 typedef compf_struct compf[1];
44 
47 
48 // MARK: macros & functions prototypes
49 
51 #define compf_set(d, a) (d)->x = (a)->x; \
52  (d)->y = (a)->y;
53 
55 #define compf_setr(d, a) (d)->x = (a); \
56  (d)->y = 0;
57 
59 #define compf_neg(d, a) (d)->x = -(a)->x; \
60  (d)->y = -(a)->y;
61 
63 #define compf_add(d, a, b) (d)->x = (a)->x + (b)->x; \
64  (d)->y = (a)->y + (b)->y;
65 
67 #define compf_addr(d, a, r) (d)->x = (a)->x + (r); \
68  (d)->y = (a)->y;
69 
71 #define compf_sub(d, a, b) (d)->x = (a)->x - (b)->x; \
72  (d)->y = (a)->y - (b)->y;
73 
75 #define compf_subr(d, a, r) (d)->x = (a)->x - (r); \
76  (d)->y = (a)->y;
77 
78 #define compf_mul(d, a, b) coeff_t px = (a)->x * (b)->x - (a)->y * (b)->y; \
79  (d)->y = (a)->x * (b)->y + (a)->y * (b)->x; \
80  (d)->x = px;
81 
83 #define compf_mulr(d, a, r) (d)->x = (a)->x * (r); \
84  (d)->y = (a)->y * (r);
85 
87 #define compf_amr(d, a, r) (d)->x += (a)->x * (r); \
88  (d)->y += (a)->y * (r);
89 
91 #define compf_sqr(d, a) coeff_t px = (a)->x * (a)->x - (a)->y * (a)->y; \
92  (d)->y = 2 * (a)->x * (a)->y; \
93  (d)->x = px;
94 
96 #define compf_div(d, a, b) { \
97  coeff_t m2 = compf_mod2(b); \
98  coeff_t px = ((a)->x * (b)->x + (a)->y * (b)->y) / m2; \
99  (d)->y = ((a)->y * (b)->x - (a)->x * (b)->y) / m2; \
100  (d)->x = px;\
101  }
102 
104 #define compf_mod(a) fhypot((a)->x, (a)->y)
105 
107 #define compf_dist(a, b) fhypot((a)->x - (b)->x, (a)->y - (b)->y)
108 
111 #define compf_mod2(a) ((a)->x * (a)->x + (a)->y * (a)->y)
112 
114 #define compf_log2(a) (plog2(compf_mod(a)))
115 
117 #define coeff_log2(a) (plog2((a) < 0 ? -(a) : (a)))
118 
120 #define compf_s(a) (pfloor(plog2(compf_mod(a))) + 1)
121 
123 #define coeff_s(a) (pfloor(coeff_log2(a)) + 1)
124 
125 #endif /* compf_h */
compf_struct compf[1]
Practical wrapper for compf_struct.
Definition: compf.h:43
compf_struct * compf_ptr
Convenience pointer to compf_struct.
Definition: compf.h:46
Definition of basic types.
double coeff_t
The machine number type to use for polynomial coefficients and evaluation.
Definition: ntypes.h:81
Machine complex numbers.
Definition: compf.h:29
coeff_t y
the imaginary part of the complex number
Definition: compf.h:31
coeff_t x
the real part of the complex number
Definition: compf.h:30