Fix saving lists of arrays with recent versions of numpy
[qpms.git] / qpms / kahansum.h
blob80ce4a7bfa02a87212cd8867b493a330fcfc6fb6
1 /*! \file kahansum.h
2 * \brief Inline functions providing Kahan summation.
3 */
4 #ifndef KAHANSUM_H
5 #define KAHANSUM_H
7 #include <complex.h>
9 static inline void kahaninit(double * const sum, double * const compensation) {
10 *sum = 0;
11 *compensation = 0;
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;
22 static inline void ckahaninit(complex double * const sum, complex double * const compensation) {
23 *sum = 0;
24 *compensation = 0;
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;
34 #endif //KAHANSUM_H