Skip to content

test(material): the direction table matches libm to within its last place, on any libm - #152

Merged
transfix merged 1 commit into
mainfrom
fix/gate-dirs-any-libm
Nov 3, 2026
Merged

transfix merged 1 commit into
mainfrom
fix/gate-dirs-any-libm

Conversation

@transfix

@transfix transfix commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

test_direction_table_is_exact_and_matches_math failed on Windows, so this PR loosens the test to match the design. Nothing outside the test changes.

Why it failed. The 16-direction table in grl_snam/material.py is the bit contract shared verbatim with the C++ twin, which is exactly why it is a table of constants: libm's sin/cos stay out of the contract. The test nonetheless asserted each entry equal to the running host's math.sin/math.cos bit for bit. MSVC's CRT rounds sin(pi/4) the other way from glibc (0.7071067811865476 against the table's 0.7071067811865475), so the assertion fails there.

The change. The test now checks each entry against math.sin/math.cos to within one ulp of 1.0. It still checks that the length is 1 to within 1e-15, and that gate_directions(16) is the table itself.

Tested: tests/test_material_gate_sim.py passes, 12 tests, on Windows (Python 3.11).

…t place, on any libm

The table is the bit contract shared verbatim with the C++ twin precisely so libm's sin/cos stay
out of it, but the test asserted it equal to the host's math.sin/math.cos bit for bit. MSVC's CRT
rounds sin(pi/4) the other way from glibc (0.7071067811865476 vs the table's ...475), so the test
failed on Windows. It now checks each entry to within one ulp of 1.0.
@transfix
transfix merged commit b935bec into main Nov 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant