An Orbit in Whole Numbers, and the Same Bytes After a Hundred Million Steps
Two simulations that propagate the same orbit from the same initial state with the same integrator should arrive at the same place. In floating point, they often do not, quite. IEEE 754 specifies each operation to the bit, but what a compiler makes of an expression is not specified: one compiler fuses a multiply and an add into a single instruction with one rounding (a fused multiply-add, FMA) and another keeps them separate; one math library's square root differs from another's in the last bit. After enough steps, the two trajectories are different numbers. In a distributed simulation, where federates on different machines may each carry a copy of a state, that is a disagreement nobody chose.
This paper propagates an orbit in checked integer arithmetic in cint, where each operation has exactly one answer. After a hundred million steps, four compilers on three machines produce the same bytes. The same integrator in double, built with the same compilers, does not agree with itself. The paper also shows what that costs: the checked integer program runs 25 to 44 times slower than the double one.
- steps
- 100,000,000 (3.17 years at 1 s)
- builds
- GCC 13.3.0, Clang 18.1.3, MSVC 19.44, Apple Clang 21.0.0
- state.digest
- 15231276719831660197 (4/4 equal)
- double.drift
- 93.4 cm (GCC -ffp-contract=fast vs -ffp-contract=off)
two kinds of error
Accuracy and reproducibility are easy to run together, and this paper keeps them apart.
- Truncation error belongs to the integrator. A first-order method with a fixed one-second step puts the vessel a few kilometers from where the exact solution would, and it does so identically on every machine, because it is a property of the method, not of the hardware.
- Reproducibility is whether two machines running the same method get the same bits.
Floating point can fail the second even when both machines pass the first by the same margin. Integer arithmetic has only the first. The orbit below is not more accurate than its floating-point twin, and this paper does not say it is. It is the same everywhere.
the program
The program models a circular Earth orbit at a radius of 6,778.137 km, one second per step, with semi-implicit Euler: kick the velocity by gravity, then drift the position by the new velocity. Position is in centimeters and velocity in micrometers per second. The part of a step smaller than a centimeter is carried in a remainder of its own, so nothing is dropped and the position is exact to the micrometer.
Gravity is GM / r², with r from an integer square root. Its magnitude and its two components are three muldiv calls, each of which keeps the product wide and rounds once, by name. The radius squared in centimeters is about 4.6 × 1017, inside I64 with room to spare, and that is the whole reason for the units: they were chosen so that every intermediate fits, and if one did not, the program would stop and say which. A digest of every state is folded along the way. It wraps on purpose, marked with the wrapping operators, because it is a fingerprint and not a quantity.
// a two-body orbit stepped in whole numbers, position is centimeters
// with a micrometer remainder carried separately so nothing is lost,
// velocity is micrometers per second, the step is one second and the
// integrator is semi-implicit euler, after one period the program
// prints how far the vessel is from where it started and a digest of
// every state it passed through
const I64 GM = 398_600_441_800_000; // earth, m^3/s^2
const I64 STEPS = 5_554; // about one period at this radius
void main() {
I64 x = 677_813_700; I64 y = 0; // cm, 6,778.137 km
I64 vx = 0; I64 vy = 7_668_558_000; // um/s, circular speed
I64 rx = 0; I64 ry = 0; // sub-centimeter remainders, um
I64 x0 = x; I64 y0 = y;
I64 rmin = 9_223_372_036_854_775_807; I64 rmax = 0;
U64 digest = 0;
for i in 0..STEPS {
// gravity: GM / r^2 in um/s^2, then split along x and y
I64 r2 = x * x + y * y; // cm^2
I64 r = isqrt(r2); // cm
I64 g = muldiv(I64, GM, 10_000_000_000, r2, half_even); // (m^3/s^2 * 1e10) / cm^2 = um/s^2
I64 ax = -muldiv(I64, g, x, r, half_even);
I64 ay = -muldiv(I64, g, y, r, half_even);
// kick, then drift, carrying the remainder exactly
vx = vx + ax; vy = vy + ay;
rx = rx + vx; ry = ry + vy;
x = x + rx / 10_000; rx = rx % 10_000;
y = y + ry / 10_000; ry = ry % 10_000;
rmin = min(rmin, r); rmax = max(rmax, r);
// the digest wraps on purpose, it is a fingerprint of the path, not a quantity
digest = (digest *% 1_099_511_628_211) ^ (x as% U64) ^ ((y as% U64) <<% 21) ^ ((vx as% U64) <<% 42) ^ ((vy as% U64) <<% 7);
}
I64 dx = x - x0; I64 dy = y - y0;
"after {STEPS} s: x {x} cm, y {y} cm, vx {vx} um/s, vy {vy} um/s\n";
"radius stayed between {rmin} and {rmax} cm\n";
"distance from the start {isqrt(dx * dx + dy * dy)} cm\n";
"state digest {digest}\n";
}
test "the remainder never holds a whole centimeter" {
for i in 0..4_001 {
I64 v = i * 7_919 - 15_838_000; // -15.8 m to +15.8 m in um, both signs
assert(v % 10_000 >= 0 && v % 10_000 < 10_000 && v / 10_000 * 10_000 + v % 10_000 == v);
}
}
run with the reference of cint 0.2.8, from ref/ of the release: python -m cint_ref run --stdout /dev/stdout orbit.ci
stdoutafter 5554 s: x 677813482 cm, y 284550 cm, vx -3219363 um/s, vy 7668559130 um/s
radius stayed between 677430672 and 678197536 cm
distance from the start 284550 cm
state digest 9251917315907225461
outcome recordcase orbit
source reference
outcome value
stdout-bytes 196
stdout-sha256 d2b4d07efa7dda4019e55138d3da0d41c0155233af360da18aeceafa3d0c76b1
fuel-consumed 5555
what the output shows
The program runs one period, 5,554 steps. The vessel comes back to within 2.85 km of its start: the truncation error of a one-second first-order step, plus the fact that 5,554 seconds is not exactly the period. The radius stays within 3.9 km of its starting value through the whole orbit, the bounded oscillation this integrator is known for.
The fourth line prints the state digest. Run the program twice and the digest is the same. Run it compiled and the digest is the same. Change the step or the starting speed and it changes, as it should.
cint_ref with one print line added. It swings between 6,774.307 and 6,781.975 km once per orbit, the oscillation of the semi-implicit step. The dashed lines mark the range over all 10⁸ steps of the compiled run, 6,774.295 to 6,781.985 km: after about 18,000 orbits it reaches 11.6 m lower and 9.7 m higher than the first orbit did.data
| second | radius, km |
|---|---|
| 0 | 6,778.137 |
| 100 | 6,777.704 |
| 200 | 6,777.277 |
| 300 | 6,776.861 |
| 400 | 6,776.461 |
| 500 | 6,776.082 |
| 600 | 6,775.730 |
| 700 | 6,775.409 |
| 800 | 6,775.122 |
| 900 | 6,774.875 |
| 1,000 | 6,774.669 |
| 1,100 | 6,774.507 |
| 1,200 | 6,774.392 |
| 1,300 | 6,774.325 |
| 1,400 | 6,774.307 |
| 1,500 | 6,774.338 |
| 1,600 | 6,774.418 |
| 1,700 | 6,774.545 |
| 1,800 | 6,774.718 |
| 1,900 | 6,774.935 |
| 2,000 | 6,775.193 |
| 2,100 | 6,775.489 |
| 2,200 | 6,775.819 |
| 2,300 | 6,776.178 |
| 2,400 | 6,776.563 |
| 2,500 | 6,776.968 |
| 2,600 | 6,777.387 |
| 2,700 | 6,777.817 |
| 2,800 | 6,778.250 |
| 2,900 | 6,778.682 |
| 3,000 | 6,779.107 |
| 3,100 | 6,779.520 |
| 3,200 | 6,779.915 |
| 3,300 | 6,780.287 |
| 3,400 | 6,780.632 |
| 3,500 | 6,780.945 |
| 3,600 | 6,781.222 |
| 3,700 | 6,781.460 |
| 3,800 | 6,781.655 |
| 3,900 | 6,781.806 |
| 4,000 | 6,781.910 |
| 4,100 | 6,781.965 |
| 4,200 | 6,781.972 |
| 4,300 | 6,781.930 |
| 4,400 | 6,781.839 |
| 4,500 | 6,781.702 |
| 4,600 | 6,781.518 |
| 4,700 | 6,781.292 |
| 4,800 | 6,781.025 |
| 4,900 | 6,780.722 |
| 5,000 | 6,780.385 |
| 5,100 | 6,780.020 |
| 5,200 | 6,779.631 |
| 5,300 | 6,779.222 |
| 5,400 | 6,778.800 |
| 5,500 | 6,778.370 |
a hundred million steps
The same program with the step count raised to 100,000,000, about 18,000 orbits and three years of simulated time, was emitted to C by cintc once and built with four compilers on three machines (an x86-64 Linux host, an x86-64 Windows 11 host, and an arm64 Mac), each at -O2 (/O2 for MSVC):
| build | machine | final position, cm | state digest |
|---|---|---|---|
| clang 18.1.3 | x86-64 Linux | 24,708,944 676,979,337 | 15231276719831660197 |
| gcc 13.3.0 | x86-64 Linux | 24,708,944 676,979,337 | 15231276719831660197 |
| MSVC 19.44 | x86-64 Windows 11 | 24,708,944 676,979,337 | 15231276719831660197 |
| Apple Clang 21.0.0 | arm64 macOS 27 | 24,708,944 676,979,337 | 15231276719831660197 |
Every byte of output is identical across the four builds, the final position and digest included, and so is its SHA-256, 68d2475161b0946c69e0373f6dbd50768ac17848e30c848ed6aa16df96608a7a. Over the three simulated years, the radius stayed between 6,774.295 and 6,781.985 km. How long each build took, beside the same loop in double, is in what the checking costs, below.
the same integrator in double
For comparison, thirty lines of C run the same integrator in double: the same state, step, kick and drift, in meters and meters per second, with the same digest folded over the bit patterns of the state. Built four ways on the same machine, for the same hundred million steps:
| build | fused multiply-add | time | final x, m | state digest |
|---|---|---|---|---|
| clang -O2 -ffp-contract=off | off | 1.5 s | 228619.66286548352 | 7140356435394844241 |
| clang -O2 -ffp-contract=fast -mfma | allowed | 1.6 s | 228619.66286548352 | 7140356435394844241 |
| gcc -O2 -ffp-contract=off | off | 1.5 s | 228619.66286548352 | 7140356435394844241 |
| gcc -O2 -mfma | gcc's default | 1.4 s | 228618.73339447728 | 295821013259388869 |
Three of the four agree and the fourth does not. gcc, at its default contraction setting (-ffp-contract=fast in GNU C mode) with fused multiply-add available, puts the vessel 93 cm from where the other three put it, after the same hundred million steps of the same source on the same processor, and its digest shares nothing with theirs. None of the four is wrong. Each is a correct compilation of a program whose result C leaves to the compiler, which may contract a floating-point expression or not. That is the disagreement the integer version does not have.
orbit_double_checkpoints.c, built the four ways of the table.data
| step | distance, m |
|---|---|
| 3,981 | 6.98e-10 |
| 4,467 | 1.4e-09 |
| 5,012 | 1.32e-09 |
| 5,623 | 3.26e-09 |
| 6,310 | 4.66e-09 |
| 7,079 | 4.66e-09 |
| 7,943 | 7.09e-09 |
| 8,913 | 2.06e-08 |
| 10,000 | 4.68e-08 |
| 11,220 | 5.76e-08 |
| 12,589 | 9.05e-08 |
| 14,125 | 2.94e-07 |
| 15,849 | 6.1e-07 |
| 17,783 | 9.46e-07 |
| 19,953 | 1.52e-06 |
| 22,387 | 2.29e-06 |
| 25,119 | 3.22e-06 |
| 28,184 | 3.97e-06 |
| 31,623 | 4.31e-06 |
| 35,481 | 5.5e-06 |
| 39,811 | 6.61e-06 |
| 44,668 | 7.88e-06 |
| 50,119 | 9.7e-06 |
| 56,234 | 1.25e-05 |
| 63,096 | 1.54e-05 |
| 70,795 | 1.81e-05 |
| 79,433 | 2.39e-05 |
| 89,125 | 2.97e-05 |
| 100,000 | 3.58e-05 |
| 112,202 | 4.87e-05 |
| 125,893 | 6.5e-05 |
| 141,254 | 8.66e-05 |
| 158,489 | 0.000112 |
| 177,828 | 0.000142 |
| 199,526 | 0.000176 |
| 223,872 | 0.000219 |
| 251,189 | 0.000273 |
| 281,838 | 0.000336 |
| 316,228 | 0.000411 |
| 354,813 | 0.000505 |
| 398,107 | 0.00061 |
| 446,684 | 0.000723 |
| 501,187 | 0.000828 |
| 562,341 | 0.000887 |
| 630,957 | 0.000912 |
| 707,946 | 0.000897 |
| 794,328 | 0.000795 |
| 891,251 | 0.000668 |
| 1,000,000 | 0.00046 |
| 1,122,018 | 0.000219 |
| 1,258,925 | 4.91e-05 |
| 1,412,538 | 0.000374 |
| 1,584,893 | 0.000802 |
| 1,778,279 | 0.00123 |
| 1,995,262 | 0.00168 |
| 2,238,721 | 0.00195 |
| 2,511,886 | 0.00222 |
| 2,818,383 | 0.00294 |
| 3,162,278 | 0.00405 |
| 3,548,134 | 0.00552 |
| 3,981,072 | 0.00694 |
| 4,466,836 | 0.00793 |
| 5,011,872 | 0.00815 |
| 5,623,413 | 0.00861 |
| 6,309,573 | 0.00829 |
| 7,079,458 | 0.00712 |
| 7,943,282 | 0.00613 |
| 8,912,509 | 0.00703 |
| 10,000,000 | 0.0119 |
| 11,220,185 | 0.0158 |
| 12,589,254 | 0.0227 |
| 14,125,375 | 0.0346 |
| 15,848,932 | 0.047 |
| 17,782,794 | 0.0585 |
| 19,952,623 | 0.0714 |
| 22,387,211 | 0.0878 |
| 25,118,864 | 0.0941 |
| 28,183,829 | 0.106 |
| 31,622,777 | 0.13 |
| 35,481,339 | 0.165 |
| 39,810,717 | 0.221 |
| 44,668,359 | 0.272 |
| 50,118,723 | 0.305 |
| 56,234,133 | 0.33 |
| 63,095,734 | 0.393 |
| 70,794,578 | 0.509 |
| 79,432,823 | 0.631 |
| 89,125,094 | 0.792 |
| 100,000,000 | 0.93 |
The table below runs the same thirty lines on the other two machines, plus clang on the first machine with its vectorizer off:
| build | machine | final x, m | state digest |
|---|---|---|---|
| Apple Clang -O2 -ffp-contract=off | arm64 macOS | 228619.66286548352 | 7140356435394844241 |
| Apple Clang -O2 | arm64 macOS | 228618.73339447728 | 295821013259388869 |
| Apple Clang -O2 -ffp-contract=fast | arm64 macOS | 228618.70278263546 | 7708669496574730328 |
| MSVC /O2 /fp:precise | x86-64 Windows | 228619.66286548352 | 7140356435394844241 |
| MSVC /O2 /fp:contract | x86-64 Windows | 228619.66286548352 | 7140356435394844241 |
| MSVC /O2 /fp:fast | x86-64 Windows | 228619.57162821386 | 2618997089874377949 |
| clang -O2 -ffp-contract=fast -mfma -fno-slp-vectorize | x86-64 Linux | 228618.70278263546 | 7708669496574730328 |
- On arm64 the fused multiply-add is always available, and Apple Clang's default build uses it: it lands on gcc's answer from the first table, to the bit.
- Allowed to fuse wherever it likes (
-ffp-contract=fast), Apple Clang gives a third answer. - MSVC's fast mode (
/fp:fast) gives a fourth. - The clang build in the first table that was allowed to fuse, and still agreed with the unfused builds, did so because clang packed x and y into one vector register and fused nothing there. With that vectorizer off (
-fno-slp-vectorize) it fuses, and gives the third answer too.
That is four answers from one source, every one a correct compilation. The integer program gave one answer on all four compilers.
what the checking costs
Determinism has a measurable cost. The table below compares the hundred-million-step program against the thirty lines of double, each built at -O2 (/O2 for MSVC) and run once, one after the other on the same machine, with the double built unfused (-ffp-contract=off, or /fp:precise for MSVC):
| build | machine | checked integer | double | integer / double |
|---|---|---|---|---|
| clang 18.1.3 | x86-64 Linux | 44.6 s | 1.8 s | 25 |
| gcc 13.3.0 | x86-64 Linux | 49.8 s | 1.8 s | 28 |
| MSVC 19.44 | x86-64 Windows 11 | 61.2 s | 1.4 s | 44 |
| Apple Clang 21.0.0 | arm64 macOS 27 | 25.7 s | 0.9 s | 29 |
The double version is 25 to 44 times faster, depending on the compiler. A step of the integer loop takes an integer square root and three multiply-divides with a wide product, and every plain operator in it is checked; a step of the double loop takes one hardware square root and three divisions. How the time splits between the square root, the wide products and the checks has not been measured, so the ratio is the price of the whole program, with the compiler that emitted the C on this site, and not of checking alone. Each time is a single run, so the double times here differ by a few tenths of a second from the first machine's times in the double table above, which came from other runs.
same bytes from the reference and the compiler
The box below is the C that cintc emitted for the one-period program as published: 536 lines of C for 50 lines of cint. The reference, cint_ref, and the compiled program write the same four lines, with stdout SHA-256 d2b4d07efa7dda4019e55138d3da0d41c0155233af360da18aeceafa3d0c76b1, and the test passes under both.
orbit.c · emitted C17 excerpt (full source)L38_h:;
t13 = l11_i;
t14 = t13 < t12;
if (!t14) goto L38_e;
if (!cint_fuel_charge(ctx, (cint_site){0u, 2u}, 1u)) goto fault;
t15 = l0_x;
t16 = l0_x;
if (!cint_mul_i64(ctx, (cint_site){0u, 3u}, t15, t16, &t17)) goto fault;
t18 = l1_y;
t19 = l1_y;
if (!cint_mul_i64(ctx, (cint_site){0u, 4u}, t18, t19, &t20)) goto fault;
if (!cint_add_i64(ctx, (cint_site){0u, 5u}, t17, t20, &t21)) goto fault;
l12_r2 = t21;
t22 = l12_r2;
if (!cint_builtin_i64(ctx, (cint_site){0u, 6u}, 13u, CINT_TAG_I64, 0u, 0u, (uint64_t)t22, 0u, 0u, &t23)) goto fault;
l13_r = t23;
t24 = INT64_C(398600441800000);
t25 = INT64_C(10000000000);
t26 = l12_r2;
if (!cint_builtin_i64(ctx, (cint_site){0u, 7u}, 11u, CINT_TAG_I64, 5u, CINT_TAG_I64, (uint64_t)t24, (uint64_t)t25, (uint64_t)t26, &t27)) goto fault;
128 bits
orbit_wide.ci is the same orbit with the state in I128: position in micrometers in one number, with no remainder to carry, and squares of about 4.6 × 1025 with about forty bits to spare. It is the shape a state would take in a simulator that wanted femtometer remainders and planetary distances in the same word. The reference runs it. In cint 0.1.1 (when this paper was written), cintc refused I128 with C9102; cint 0.2.0 added I128 through I1024 to cintc.
what is not claimed
An earlier simulator by the same author, written in a different language, carried an orbit in integers with explicit units and rounding rules, recorded bit-identical state on x86-64 and AArch64 machines across 1.5 million per-tick digests, and published its state through the SpaceFOM. That work is cited below. This paper is the same idea in cint, in fifty lines, with the arithmetic checked by the language rather than by the program.
- The machines are one x86-64 Linux host, one x86-64 Windows host, and one arm64 Mac, so the identity shown is across four compilers and two architectures, not a survey of hardware.
- Nothing here exchanged state over HLA or spoke to a federation. The argument about distributed simulation is that two federates computing the same thing would agree, and it is made with three machines standing in for federates.
- The integrator is first-order with a one-second step, a two-body model with no drag, no oblateness, and no third body. It shows reproducibility and is not offered as an accurate propagator.
limits
The units were chosen for this orbit. A different radius or step moves the intermediates, and the first thing to do with the program is to check that they still fit, which the program itself does by faulting if they do not. The floating-point comparison is one program on three machines with four compilers. It shows that the result depends on compilation choices, which is all it is asked to show; the size of the difference, under a meter after three years, is not a measure of anything general. The digest is a fingerprint for comparing runs, not a cryptographic hash.
references
- E. Hairer, C. Lubich and G. Wanner. Geometric Numerical Integration. Springer, second edition, 2006. Chapter I, the symplectic Euler method.
- D. Goldberg. What Every Computer Scientist Should Know About Floating-Point Arithmetic. ACM Computing Surveys, 1991.
- IEEE Std 754-2019, IEEE Standard for Floating-Point Arithmetic. Section 10, expression evaluation and the fused multiply-add.
- GNU Compiler Collection, Optimize Options:
-ffp-contract, whose default in GNU C mode isfast. - SISO-STD-018-2020, Standard for Space Reference Federation Object Model (SpaceFOM): the setting in which federates carry state for one another.
- H. Little. spaceFOM-integer: a SpaceFOM federate publishing an integer-state orbital simulator over HLA, with a replay verifier for bit-identical results across platforms. github.com/pennyleans/spaceFOM-integer, 2026.
cite as
Harriett Little. An Orbit in Whole Numbers, and the Same Bytes After a Hundred Million Steps. integerc.dev, 2026. https://integerc.dev/papers/orbit/
Harriett Little · 2026-10-06