Repository navigation
Conversation
tin.py takes its logarithms and exponentials from Python's math module, i.e. the C library. Rust's f64::ln/exp use the C library of the target as well, so TINs differed from tin.py's in the last digit on some platforms (macOS, musl) and, on glibc, depended on whether the CPU has FMA: glibc picks different builds of log and exp (__ieee754_log_fma, __ieee754_exp_fma) that round differently for about 1 in 10 000 inputs, which changes about one TIN in a thousand and can move the summary digits. Add bit-exact ports of glibc 2.39's FMA log and exp (the builds glibc selects on every x86-64 CPU with FMA and AVX2, and whose results aarch64 matches), and use them in compute_tin. The code follows sysdeps/ieee754/dbl-64/e_log.c and e_exp.c with f64::mul_add at the points where GCC fused a*b+c in glibc's FMA builds, read from the machine code of libm. The ports match glibc's FMA path and Python's math.log/math.exp on 7 million inputs (random bit patterns, near 1, subnormals, c/total), and the TINs tin.py prints, on every platform. The NumPy-based summary needs no change: add.reduce uses the same scalar pairwise sum under every CPU dispatch target. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
Author
|
Closing per review: this only matters for the last digit of ~1 TIN value in 8,000 on machines whose libm doesn't match glibc's FMA path. RustQC's Docker image (glibc) already matches tin.py exactly on any modern x86-64 or ARM machine, so the benchmarks keep an exact TIN check without vendoring glibc's log/exp. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tin.py computes TIN with Python's
math.log/math.exp, which come from glibc. glibc picks a different build of these at runtime depending on the CPU (an FMA build on x86-64 CPUs with FMA+AVX2, a generic build otherwise), and the two round differently in the last bit for about 1 in 10,000 inputs. RustQC called Rust'sln/exp, so its TIN values inherited the same machine dependence, and differed from tin.py in the last digit for roughly 1 transcript in several thousand depending on where each ran (macOS and musl differ again).This adds a port of glibc 2.39's FMA
logandexp, usingmul_addexactly where glibc's FMA code fuses, and uses it for TIN. That's the build every x86-64 CPU from the last decade uses, and aarch64 glibc gives the same bits, so RustQC's TIN is now identical on every platform and equal to tin.py's on both.math.log/math.expbit for bit on 7.25M inputs (random, near 1, subnormal, boundary exponents); as a control, glibc's generic build differs from it on 1,238 of them.tin.xlsandsummary.txtare byte-identical to RSeQC 5.0.4 tin.py on four datasets at 1, 2 and 6 threads.🤖 Generated with Claude Code