Skip to content

twoProductError

twoProductError(a, b, product): number

Defined in: two-product.ts:34

The exact rounding error of product, where product is the binary64 result of a * b — so a * b === product + twoProductError(a, b, product) with no error at all.

Dekker’s two-product, one of the error-free transformations: each operand is split into two halves narrow enough that their pairwise products are exact, and the discarded bits are reassembled from them. Seventeen operations, no branch on the common path, and no allocation.

The caller passes product rather than receiving it because JavaScript has no multiple return values, and an object or tuple would allocate on every call — unacceptable in the per-element loops this exists for.

Operands above 2 ** 996 are scaled by a power of two first, which is exact, so the whole finite range works. Two limits remain: if a * b overflowed there is no error term to recover and the result is NaN, and if the exact product is subnormal the error term loses the bits that underflowed.

number

First factor, exactly as passed to the multiplication.

number

Second factor, exactly as passed to the multiplication.

number

The binary64 result of a * b.

number

The part of a * b that product dropped.