Notes on evaluating Δ_n factor in the lattice sums.
[qpms.git] / qpms / kahansum.h
blob6dcde178f718647d60671538c6fe9e92402265a5
1 #ifndef KAHANSUM_H
2 #define KAHANSUM_H
4 #include <complex.h>
6 static inline void kahaninit(double * const sum, double * const compensation) {
7 *sum = 0;
8 *compensation = 0;
11 static inline void kahanadd(double *sum, double *compensation, double input) {
12 double compensated_input = input - *compensation;
13 double nsum = *sum + compensated_input;
14 *compensation = (nsum - *sum) - compensated_input;
15 *sum = nsum;
19 static inline void ckahaninit(complex double * const sum, complex double * const compensation) {
20 *sum = 0;
21 *compensation = 0;
24 static inline void ckahanadd(complex double *sum, complex double *compensation, complex double input) {
25 complex double compensated_input = input - *compensation;
26 complex double nsum = *sum + compensated_input;
27 *compensation = (nsum - *sum) - compensated_input;
28 *sum = nsum;
31 #endif //KAHANSUM_H