QPMS
Electromagnetic multiple scattering library and toolkit.
kahansum.h
Go to the documentation of this file.
1 
4 #ifndef KAHANSUM_H
5 #define KAHANSUM_H
6 
7 #include <complex.h>
8 
9 static inline void kahaninit(double * const sum, double * const compensation) {
10  *sum = 0;
11  *compensation = 0;
12 }
13 
14 static inline void kahanadd(double *sum, double *compensation, double input) {
15  double compensated_input = input - *compensation;
16  double nsum = *sum + compensated_input;
17  *compensation = (nsum - *sum) - compensated_input;
18  *sum = nsum;
19 }
20 
21 
22 static inline void ckahaninit(complex double * const sum, complex double * const compensation) {
23  *sum = 0;
24  *compensation = 0;
25 }
26 
27 static inline void ckahanadd(complex double *sum, complex double *compensation, complex double input) {
28  complex double compensated_input = input - *compensation;
29  complex double nsum = *sum + compensated_input;
30  *compensation = (nsum - *sum) - compensated_input;
31  *sum = nsum;
32 }
33 
34 #endif //KAHANSUM_H