Skip to content

Add toDouble for the FastInt family - #6592

Closed
meshinspector-agent[bot] wants to merge 1 commit into
alpha-shape-triangle-shadowfrom
agent/mlib-fastint-to-double
Closed

Add toDouble for the FastInt family#6592
meshinspector-agent[bot] wants to merge 1 commit into
alpha-shape-triangle-shadowfrom
agent/mlib-fastint-to-double

Conversation

@meshinspector-agent

Copy link
Copy Markdown
Contributor

First of the three increments that restore the shadow filter's double pre-filters. They were dropped in the port because the FastInt family has no conversion to double — on MSVC FastInt128 is std::_Signed128, which has no such operator at all — so every shadow test is currently exact.

What changed

  • toDouble( FastInt128 ) and toDouble( const FastInt<nBits> & ), both over one shared detail::doubleFromWords.
  • Correctly rounded: exact below 2^53, relative error below 2^-53 above it, ±inf past DBL_MAX. The bound is documented at the function, since a pre-filter that rejects a case in double is only safe against a stated conversion error.
  • Deliberately not the built-in __int128_t → double on gcc/clang: the same code on every platform, so the filter's numbers cannot diverge between MSVC and the rest.
  • Class comments in MRFastInt.h / MRFastInt128.h no longer claim the conversion is missing.

Correct rounding comes from a single std::uint64_t → double (itself correctly rounded) of the top 64 significant bits, with everything below folded into a sticky lowest bit — so a tie is told from a value just above it without a second rounding.

No caller yet: increments 2 and 3 consume it.

Verification

  • Built MRTest in Release with g++-12 in the ubuntu22 image, mirroring build-test-ubuntu-x64.yml (prebuilt thirdparty linked, Python bindings off) — clean.
  • Full MRTest: 354/354 pass, including MRAlphaShapeTests and the InSphere/SoS predicate tests.
  • 7 new tests in MRFastIntTests.cpp, against that file's existing RefInt oracle rather than any code under test:
    • exactness below 2^53 at every width, and +0 for zero;
    • per value: the result is nearest — neither std::nextafter neighbour is closer — and within the documented 2^-53;
    • the tie cases at 2^53 (round-to-even both ways) and the sticky-bit tie at 2^64 + 2^11, which only a correct tail test gets right;
    • sign symmetry, and the same value at different widths converting to the same double;
    • ±inf past DBL_MAX — reachable only through a product, since a 1024-bit value maxes at 2^1023 < DBL_MAX, so FastInt<2048> and max1024 * max1024 cover it.
  • Not exercised here: MSVC's std::_Signed128 path (no Windows box on this runner) — sharing one word-based implementation is precisely what makes that path the same code; CI covers it. No UI surface and nothing to drive in the viewer: a header-only numeric addition with no caller until the next increment, so behaviour is unchanged at runtime.
  • No timings from this box — it is not a GitHub-hosted runner.

CI label: none. build-test-distribute.yml is gated on pull_request: branches: [ master ], so a PR based on alpha-shape-triangle-shadow gets no checks by design; the numbers come from the branch run after the squash-merge.

The pre-filters that reject a case in double before evaluating it exactly
need a bignum-to-double conversion, which the family lacked: MSVC's
std::_Signed128 has no such operator at all. It is correctly rounded, and
deliberately platform-independent rather than deferring to the built-in
__int128_t conversion, since the stated error bound is what makes those
rejections safe.
@meshinspector-agent

Copy link
Copy Markdown
Contributor Author

Superseded by #6594 — same commit rebased onto master, so it actually gets checks. Force-push to agent/* is blocked by a repo rule, hence a new branch rather than a rebase in place. Branch kept alive because #6593 is based on it.

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.

0 participants