mirror of
https://github.com/godotengine/godot.git
synced 2024-12-03 09:52:18 +08:00
bf05309af7
As requested by reduz, an import of thekla_atlas into thirdparty/
40 lines
669 B
C++
40 lines
669 B
C++
// 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
|