summaryrefslogtreecommitdiff
path: root/thirdparty/thekla_atlas/nvmath/KahanSum.h
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/thekla_atlas/nvmath/KahanSum.h')
-rw-r--r--thirdparty/thekla_atlas/nvmath/KahanSum.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/thirdparty/thekla_atlas/nvmath/KahanSum.h b/thirdparty/thekla_atlas/nvmath/KahanSum.h
new file mode 100644
index 0000000000..18d475e7cb
--- /dev/null
+++ b/thirdparty/thekla_atlas/nvmath/KahanSum.h
@@ -0,0 +1,39 @@
+// This code is in the public domain -- Ignacio Castaņo <castano@gmail.com>
+
+#pragma once
+#ifndef NV_MATH_KAHANSUM_H
+#define NV_MATH_KAHANSUM_H
+
+#include "nvmath.h"
+
+namespace nv
+{
+
+ class KahanSum
+ {
+ public:
+ KahanSum() : accum(0.0f), err(0) {};
+
+ void add(float f)
+ {
+ float compensated = f + err;
+ float tmp = accum + compensated;
+ err = accum - tmp;
+ err += compensated;
+ accum = tmp;
+ }
+
+ float sum() const
+ {
+ return accum;
+ }
+
+ private:
+ float accum;
+ float err;
+ };
+
+} // nv namespace
+
+
+#endif // NV_MATH_KAHANSUM_H