A diagnostic report may sum signed residuals over a robot test run. If large positive and negative terms nearly cancel, the final value can depend on how intermediate results are stored. A user looking only at the final total might conclude that the signed residuals balance exactly. The same input can produce a small nonzero balance when the reduction preserves information that a rounded subtotal discards.

The example uses three invented values and was checked in Python 3.14.7. The numerical range is deliberately extreme to make the lost term easy to see. It is neither a typical sensor range nor a recommendation for the units of a robot test. All three terms are treated as quantities in a common unit.

See how a running total loses the small term

At the positive binary floating-point value 2 to the power of 53, the next larger representable Python float in the fixture is two units away. Adding one sits halfway between those two values. Under the tested rounding behavior, the sum rounds back to the original large value. When the large negative term is then added, the running total is zero.

import math

from fractions import Fraction

large = float(2**53)

residuals = [large, 1.0, -large]

assert math.ulp(large) == 2.0

total = 0.0

for value in residuals:

total += value

assert total == 0.0

assert sum(map(Fraction, residuals)) == 1

The loop deliberately performs one floating-point addition at a time. It does not describe how every library's summation routine groups terms. The rational reference converts each already stored float to its exact ratio and adds the ratios without intermediate floating-point rounding. In this fixture the three values were themselves exactly representable, so the reference result is also the sum of the intended inputs.

Compare full-stream summation with chunk subtotals

Python's math.fsum tracks several intermediate partial sums to produce a more accurate floating-point total. In the executable example, supplying all three values to a single call yields 1.0. But dividing the inputs into chunks and dropping each chunk's internal information can yield a different result, even when every separate sum uses fsum.

full = math.fsum(residuals)

subtotal_a = math.fsum(residuals[:2])

subtotal_b = math.fsum(residuals[2:])

combined = math.fsum([subtotal_a, subtotal_b])

assert full == 1.0

assert subtotal_a == large and subtotal_b == -large

assert combined == 0.0

The first chunk's exact subtotal lies between two representable floats, so the reported subtotal has already dropped the single-unit contribution. The final reducer only receives the two large values. Its zero is the correct sum of the values it received. The small term cannot be reconstructed from those two scalars.

A file boundary therefore matters when it is also a numerical reduction boundary. If the job can stream individual residuals across files, it can feed one fsum call with a generator that yields the terms in sequence. That avoids creating a rounded subtotal for each file. If workers must send summaries instead, define what those summaries preserve. An exact fixed-point integer count works when the source explicitly defines a scale and values can be represented in that scale. Other reduction schemes may retain more than one partial term and need validation across different partition sizes.

In this specific example, aggregating the two large terms together first gives zero. Adding the small term from a separate chunk then preserves 1.0. This is a useful test of partition sensitivity, although a production job should not rely on a lucky grouping. A scheduler, file size, or retry boundary can change which terms meet in a subtotal.

canceling = math.fsum([large, -large])

regrouped = math.fsum([canceling, 1.0])

assert canceling == 0.0 and regrouped == 1.0

The small term must reach the reduction

Accurate summation cannot restore a value that was already rounded away upstream. The following expression constructs large plus one before passing the result to fsum. The computation rounds at that earlier addition, so the function receives two values that already cancel.

formed_early = [large + 1.0, -large]

assert math.fsum(formed_early) == 0.0

For a robot log, this distinction can matter if a small correction is combined with a large baseline before export. Keeping the correction in its own field can preserve it for downstream arithmetic. Set the numeric scale where the quantity is defined and retain the fields needed to check the transformation. A downstream tool cannot distinguish two original values that were mapped to the same stored float.

Verify the error budget where the result is used

Keep a small reference case in which cancellation makes the expected total easy to calculate. Try different chunk boundaries with the same inputs. The result should agree within the numerical tolerance required by the report. A tolerance defined only relative to a nearly zero result can be hard to interpret. Use the residual's units and its role in the test to set an appropriate absolute tolerance as well.

Also check for missing or nonfinite data before treating a sum as a complete run. A summation method improves arithmetic on the terms it receives. It does not decide whether each term belongs in the run or whether any measurements are missing. Python's documentation describes platform-dependent details of fsum accuracy, so record the runtime when comparing exact regression outputs. When validation needs a reference independent of the floating-point reduction, use exact arithmetic on a small case with a documented input representation.

Sources checked November 28, 2026

Python 3.14 documentation, math

https://docs.python.org/3.14/library/math.html

Python 3.14 tutorial, Floating-Point Arithmetic

https://docs.python.org/3.14/tutorial/floatingpoint.html

Python 3.14 documentation, fractions

https://docs.python.org/3.14/library/fractions.html

Illustration. AI-generated concept showing opposite large contributions and a small residual.