class gpr::linalg::ExactSum¶
Overview¶
#include <gpr/linalg/ExactSum.h>
class ExactSum {
public:
// structs
struct Factor;
// fields
static int kLimbs = 169;
static int kOrigin = 2148;
static int kDoubleShift = 1074;
// construction
ExactSum();
// methods
void add(double x);
void addProduct(double a, double b);
void addTripleProduct(double a, double b, double c);
void assignLimbs(const std::int64_t* digits);
void merge(const ExactSum& other);
void normalize();
std::int64_t* limbs();
const std::int64_t* limbs() const;
double nonfinite() const;
void setNonfinite(double value);
double value() const;
};
Detailed Documentation¶
Fields¶
static int kLimbs = 169
Digits of 32 bits; digit k has weight 2^(32 k - 2148). Bit 0 is the product of two minimum subnormals. A product of two maximum finite doubles sits below 2^2048. A product of three sits below 2^3072, and a long sum of those products stays below 2^3104. Digits above that window absorb carries and the sign.
static int kOrigin = 2148
Bit 0 has weight 2^-kOrigin.
static int kDoubleShift = 1074
A finite double’s least bit lies this many bits above bit 0.
Methods¶
void add(double x)
Adds a double exactly. Non-finite addends are tracked separately and propagate to value().
void addProduct(double a, double b)
Adds the exact product a * b. The integer significands are multiplied in full, including when fl(a*b) overflows or underflows. A rounded product of 2^1023 with itself is infinite, and the TwoProduct residual is then not a binary64; the significand product still cancels and leaves a representable sum such as 2^-1074.
void addTripleProduct(double a, double b, double c)
Adds the exact product a * b * c. The three integer significands are multiplied in full. A rounded a * b that overflows is infinite, and the TwoProduct residual is then not a binary64, so the product is not formed in binary64 first.
void assignLimbs(const std::int64_t* digits)
Replaces the digits with canonical digits received from message passing (see limbs()).
void merge(const ExactSum& other)
Adds another accumulator exactly.
void normalize()
Carry-propagates so that digits 0..kLimbs-2 lie in [0, 2^32). The representation is then canonical: equal sums have equal digits.
std::int64_t* limbs()
Canonical digits for message passing: normalize(), then limbs().
double nonfinite() const
Sum of the non-finite addends (0 when every addend was finite).
double value() const
The exact sum rounded once to the nearest double, ties to even.