Skip to content

Compare libm easings within 1e-15 on every glibc - #58

Closed
chessing234 wants to merge 1 commit into
omacom:masterfrom
chessing234:fix/easing-libm-rounding
Closed

chessing234 wants to merge 1 commit into
omacom:masterfrom
chessing234:fix/easing-libm-rounding

Conversation

@chessing234

Copy link
Copy Markdown

easing_matches_python_bit_exactly treated every glibc as one libm. glibc picks an FMA or SSE2 variant at runtime, and the goldens were recorded on an FMA machine. On a CPU without FMA, OutSine and InOutElastic differ by 1 ulp and one cubic bezier by about 2.4e-16. CPython on that same CPU matches the Rust result.

Polynomials stay bit-exact. sin, cos, sqrt, non-integer powers, and cubic beziers use the 1e-15 absolute tolerance other libcs already use.

Fixes #56

Ran the golden test here. This machine is macOS, so it takes the tolerance path rather than the glibc bit-exact path.

Made with Cursor

glibc picks an FMA or SSE2 libm at runtime, so bit-exact goldens recorded
on an FMA machine fail on a CPU without FMA even when CPython matches.
Polynomials stay bit-exact.

Fixes #56
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at b95d1f8 by Claude Opus 5.5, with a second opinion from Codex Medium and muse-spark-1.3-contributor (via pi, thinking high).

The bug is real and this does fix it. On a disposable x86_64 worker (FMA and AVX2, glibc 2.44), GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX2,-FMA forces glibc's SSE2 libm and reproduces #56 exactly on master: OutSine p=0.341 and InOutElastic p=0.396 off by 1 ulp, and CubicBezier(0.68, -0.55, 0.265, 1.55) p=0.379 off by 17 ulp in a debug build. CPython under the same tunable returns the Rust value (0x1.055235c33eb55p-1 for the OutSine sample), so the goldens are FMA-specific rather than Rust being wrong. This branch passes in both modes, debug and release, and the full ./bin/test (cargo tests, cli corpus, effect parity 354/354, tty parity 41/41, signal and resize suites) is green at this head on the worker.

But on the pinned platform the 1e-15 absolute bound also hides real transcription regressions. I seeded rewrites in src/utils/easing.rs that are identical in real arithmetic, the kind plan.md §5.20 says this test exists to catch, and ran master's test and this branch's test against each on the FMA worker:

  • InExpo 2^(10p-10) written as 2^(10(p-1)): 344 samples diverge (max 11 ulp). Master fails; this branch passes.
  • OutCirc sqrt(1-(p-1)^2) written as sqrt(p(2-p)): 343 samples (max 44 ulp). Master fails; this branch passes.
  • InOutElastic ((20p-11.125)*c5).sin() written as (20p*c5-11.125*c5).sin(): 198 samples (max 2225 ulp, 3.5e-16 absolute). Master fails; this branch passes.

Nothing else in the suite stands in for it. I ran the effect parity suite against each mutant: the InExpo one is caught by blackhole-custom and blackhole-dynamic, but the OutCirc and InOutElastic ones pass all 354 parity cases, because frame output only moves when a value crosses a rounding boundary. tests/engine_traces.rs only uses OutBack and InOutCubic, which stay bit-exact here. An absolute bound is loosest exactly where these curves spend time near zero (InExpo at small p, Elastic near its zero crossings), which is where the 2225-ulp mutant slipped through.

The measured libm difference is far narrower than the bound. Without any mutation, the SSE2 libm moves one or two samples per easing: 1 ulp for OutSine and InOutElastic, 1 ulp for CubicBezier(0.25, 0.1, 0.25, 1.0) (also seen on the FMA worker in release, the LLVM const-folding case the old comment explained), and at most 17 ulp on two samples of CubicBezier(0.68, -0.55, 0.265, 1.55). A per-class ulp bound, roughly 1 ulp for the sine, expo, circ and elastic easings and something near the measured 17 for the beziers, would pass on both libm variants and still reject all three mutants above. Both reviewers also looked at gating bit-exactness on is_x86_feature_detected!("fma"), and it does not hold: the tunables run is exactly a case where Rust sees FMA while glibc uses the SSE2 path. Which bound to pick is a decision about how much parity the test promises, so I have not pushed one.

Smaller points, none blocking on their own:

  • The comment says the list is easings that go through sin, cos, sqrt or a non-integer power, but CubicBezier only calls powf(2.0) and powf(3.0), and its 17-ulp difference comes from those. So integer-exponent pow is variant-dependent too, and the "polynomials stay bit-exact" line rests on no polynomial easing happening to differ across these 1001 samples on glibc 2.44 and two libm variants rather than on a guarantee.
  • The rewritten comment drops the note that release builds const-fold some powf calls in the bezier. The new bound still covers it, but the next person to see a debug/release bezier difference will read it as an ifunc issue.
  • The file header and test name still say bit-exact for every easing.

Codex and muse both raised the hidden-regression point. They agreed with measurements I gave them, so read that as agreement, not independent confirmation. Both independently flagged that the list's rationale contradicts CubicBezier's own code, and that CPU-feature gating fails under the tunables reproduction. A claim from muse that 17 ulp "is about 3.8e-15, not 2.4e-16" was wrong and is dismissed: the sample is about 0.083, where 17 ulp is 2.36e-16, as the PR says. CI did not run on this pull request.

What happens next is up to @chessing234 and the maintainer: the bug needs fixing, and the question is whether a tighter ulp bound should replace the 1e-15 tolerance on Linux/glibc.

@omarchybot omarchybot added the bug Something isn't working label Oct 24, 2026
@kleinbem kleinbem mentioned this pull request Nov 15, 2026
6 of 13 tasks
@chessing234 chessing234 closed this by deleting the head repository Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

easing_matches_python_bit_exactly fails on x86_64 CPUs without FMA (glibc libm variants)

2 participants