.. index:: pair: class; gpr::linalg::ExactSum .. _doxid-classgpr_1_1linalg_1_1_exact_sum: class gpr::linalg::ExactSum =========================== .. toctree:: :hidden: struct_gpr_linalg_ExactSum_Factor.rst Overview ~~~~~~~~ .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class ExactSum { public: // structs struct :ref:`Factor`; // fields static int :ref:`kLimbs` = 169; static int :ref:`kOrigin` = 2148; static int :ref:`kDoubleShift` = 1074; // construction :target:`ExactSum`(); // methods void :ref:`add`(double x); void :ref:`addProduct`(double a, double b); void :ref:`addTripleProduct`(double a, double b, double c); void :ref:`assignLimbs`(const std::int64_t* digits); void :ref:`merge`(const :ref:`ExactSum`& other); void :ref:`normalize`(); std::int64_t* :ref:`limbs`(); const std::int64_t* :target:`limbs`() const; double :ref:`nonfinite`() const; void :target:`setNonfinite`(double value); double :ref:`value`() const; }; .. _details-classgpr_1_1linalg_1_1_exact_sum: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Fields ------ .. index:: pair: variable; kLimbs .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1ada63a3027810d5ba9fc66961fc02efbd: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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. .. index:: pair: variable; kOrigin .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1a91b2db204ab6105f5fcac4c638a34221: .. ref-code-block:: cpp :class: doxyrest-title-code-block static int kOrigin = 2148 Bit 0 has weight 2^-kOrigin. .. index:: pair: variable; kDoubleShift .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1adebc660912eb6becfe975cfe07decfcd: .. ref-code-block:: cpp :class: doxyrest-title-code-block static int kDoubleShift = 1074 A finite double's least bit lies this many bits above bit 0. Methods ------- .. index:: pair: function; add .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1a27654e4ad8ce2336e31abf2ea70d55fa: .. ref-code-block:: cpp :class: doxyrest-title-code-block void add(double x) Adds a double exactly. Non-finite addends are tracked separately and propagate to :ref:`value() `. .. index:: pair: function; addProduct .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1a03de7eb340954e4d9a2f112f2764d4bb: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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. .. index:: pair: function; addTripleProduct .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1a7f5b8568dacaf33206f947d099b22b0c: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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. .. index:: pair: function; assignLimbs .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1a142a4708b9ff829f362c969c02c91e6a: .. ref-code-block:: cpp :class: doxyrest-title-code-block void assignLimbs(const std::int64_t* digits) Replaces the digits with canonical digits received from message passing (see :ref:`limbs() `). .. index:: pair: function; merge .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1af92f070b5cb0b30c701e56b946da4f47: .. ref-code-block:: cpp :class: doxyrest-title-code-block void merge(const :ref:`ExactSum`& other) Adds another accumulator exactly. .. index:: pair: function; normalize .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1adf1a24ab752f82521b0dca7251204904: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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. .. index:: pair: function; limbs .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1aaf5349ebce5190915b6a55014c78b4a7: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::int64_t* limbs() Canonical digits for message passing: :ref:`normalize() `, then :ref:`limbs() `. .. index:: pair: function; nonfinite .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1a08d8a886d9db784330cee77c1ae2701c: .. ref-code-block:: cpp :class: doxyrest-title-code-block double nonfinite() const :ref:`Sum ` of the non-finite addends (0 when every addend was finite). .. index:: pair: function; value .. _doxid-classgpr_1_1linalg_1_1_exact_sum_1a533701264f801f5e078b11a8c20e21be: .. ref-code-block:: cpp :class: doxyrest-title-code-block double value() const The exact sum rounded once to the nearest double, ties to even.