Repository navigation
Compute inverse powers of 2 instead of looking them up - #600
Merged
Merged
Conversation
Replace the 256-entry INVERSE_POWERS_OF_2 table with inv_pow2(), which builds 2^-exp from the exponent bits of a double, as Java's Util.invPow2 does. The values are bit-for-bit the same as the table's for every index; the new test checks 0 to 1022 against ldexp and pow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage Report for CI Build 45068045751Coverage increased (+0.001%) to 97.081%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
proost
approved these changes
Nov 23, 2026
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.
HLL and CPC looked up 2^-exp in a 256-entry table of doubles (
common/include/inv_pow2_table.hpp). This replaces it withinv_pow2()incommon/include/inv_pow2.hpp, which builds the double from its exponent bits, as Java'sUtil.invPow2does:(1023 - exp) << 52copied into a double withstd::memcpy(nostd::bit_castin C++11). It is exact for exp from 0 to 1022; current callers use at most 64.The computed values are bit-for-bit identical to the table's for all 256 entries. The new
common_testcase checks every exp from 0 to 1022 againststd::ldexpandstd::pow. All common, HLL and CPC tests pass under ASan and UBSan.inv_pow2_table.hppwas in the installed headers; it is replaced byinv_pow2.hpp. Code that included the old header directly would need to change, but it was an internal header.Benchmark (Apple clang, -O3, best of 7 to 9 runs; table vs computed):
🤖 Generated with Claude Code