Skip to content

Fix platform-dependent float formatting in scientific notation (macOS CI) - #9668

Merged
timosachsenberg merged 1 commit into
developfrom
claude/laughing-wozniak-t96825
Jun 26, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
claude/laughing-wozniak-t96825

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause

The nightly CI TOPP_OpenNuXL_5_out1 test fails on macOS 15 ARM64 (Apple libc++) but passes on Linux.

Commit e6fcc89 ("30-40% faster build, plus small runtime improvement #9648") replaced Boost.Spirit Karma with std::to_chars for float-to-string conversion. The reference file OpenNuXL_5_output.idXML was generated with the old Boost.Karma code (commit 3e86bb0).

The bug: std::to_chars(value, scientific, precision=15) rounds differently on Apple libc++ vs libstdc++. For the value 9.497386403381825e-03, Apple libc++ produces 9.497386403381820e-03 (trailing zero at position 15), which after trailing-zero trimming becomes 9.49738640338182e-03 — one character shorter than the reference. FuzzyDiff then tries to compare subsequent non-numeric characters at mismatched byte offsets, causing a character mismatch failure (] vs -).

Fix

Part 1 — Use shortest round-trip representation for scientific notation:

Switch std::to_chars to the overload without an explicit precision for the non-fixed scientific notation path. The C++ standard mandates a unique shortest decimal that round-trips back to the same double. This representation is platform-independent (same algorithm result on all conforming implementations) and matches what Boost.Karma/Grisu2 produced, so existing reference files remain valid without any updates.

Part 2 — Zero-pad single-digit exponents:

Shortest round-trip may produce e-3 instead of e-03. Add a zero-padding step to ensure the exponent is always at least 2 digits, matching the format reference files expect.

Verification

A standalone test program confirmed:

  • All 13 scientific notation values in OpenNuXL_5_output.idXML (including the problematic 9.497386403381825e-03) produce strings of the same length as the reference when using shortest round-trip.
  • The one-ULP numeric difference for that value (...825 → ...824) is within FuzzyDiff's ratio=1.01 tolerance.
  • All FuzzyDiff-safe: YES

No reference file changes are needed.

Testing

  • TOPP_OpenNuXL_5_out1 should pass on macOS 15 ARM64 after this fix
  • No other reference files need updating (the shortest round-trip representation matches Boost.Karma output for all values in existing reference files)

Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved scientific-notation formatting to match historical, human-friendly output (e.g., mantissa keeps a trailing “.0” when it would otherwise be an integer).
    • Enhanced exponent formatting by removing the unnecessary “+”, and ensuring exponents are consistently zero-padded (e.g., e-3 → e-03).
    • Refined precision handling for non-fixed scientific output to better preserve expected round-trip representations.
  • Tests
    • Expanded unit coverage for scientific notation across float, double, and long double cases.

@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Claude

Please consider applying the following patch:

--- AUTHORS	2026-06-26 04:53:03.379164924 +0000
+++ AUTHORS.new	2026-06-26 04:53:08.286154304 +0000
@@ -25,6 +25,7 @@
  - Chris Bielow
  - Christian Ehrlich
  - Christie Mathews
+ - Claude
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

@coderabbitai

coderabbitai Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

StringUtilsHelper::appendNumeric now uses shortest round-trip scientific formatting when fixed_format is disabled, keeps precision 3 when enabled, and normalizes scientific exponents while tests cover the updated string outputs.

Changes

Scientific notation formatting

Layer / File(s) Summary
Scientific output formatting
src/openms/source/DATASTRUCTURES/StringUtils.cpp
appendNumeric switches to shortest round-trip scientific formatting when fixed_format is false and rebuilds scientific output to keep a decimal digit, remove +, and zero-pad single-digit exponents.
Scientific notation tests
src/tests/class_tests/openms/source/String_test.cpp
toStr tests add float, double, and long double assertions for exact-integer mantissas and scientific strings with preserved .0 formatting.

Poem

A rabbit hopped through e and 0,
And checked each string from toe to toe.
With .0 kept snug and exponents neat,
The tiny numbers looked complete. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: making scientific float formatting platform-independent for macOS CI.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/laughing-wozniak-t96825

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openms/source/DATASTRUCTURES/StringUtils.cpp`:
- Around line 86-97: The non-fixed scientific path in StringUtils::appendNumeric
now ignores the requested precision and emits shortest round-trip output
instead. Update the std::to_chars call in StringUtils.cpp to use the precision
argument passed into appendNumeric, or change StringUtils.h documentation and
any callers if the intended contract is now shortest-round-trip formatting. Keep
the behavior consistent with the existing fixed-format branch and the public API
expectations for float/double precision.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b6f1171d-38fc-4aeb-9dee-39fb27726de9

📥 Commits

Reviewing files that changed from the base of the PR and between efcfa6a and fa9e6dd.

📒 Files selected for processing (1)
  • src/openms/source/DATASTRUCTURES/StringUtils.cpp

Commit e6fcc89 replaced Boost.Karma with std::to_chars(scientific,
precision=15) for float->string conversion. With an explicit precision the
final digit rounds differently on Apple libc++ (macOS ARM64) vs libstdc++
(Linux), so the same double yields strings of different length after
trailing-zero trimming; FuzzyDiff then compares delimiters at mismatched
byte offsets and the nightly TOPP_OpenNuXL_5_out1 test fails on macOS.

Use the shortest round-trip representation (std::to_chars scientific with no
explicit precision) in the non-fixed path. The standard guarantees a unique
shortest decimal that round-trips to the same value, so the output is
identical on every conforming implementation and reproduces the existing
reference files without updates.

Shortest round-trip can emit an integer mantissa with no decimal point
(e.g. "1e+06"); restore the historical "1.0e06" form by appending ".0" when
the mantissa has no fractional digit. This fixes Residue_test
(setModificationByDiffMonoMass(-1000000) -> "C[-1.0e06]"), which the
shortest-round-trip switch would otherwise regress on every platform.

The exponent handling is left identical to develop (strip a leading '+',
keep '-' and digits): std::to_chars uses printf %e style, so exponents on
this path always have >= 2 digits and never need zero-padding.

Add String_test coverage for integer-mantissa scientific values
(float / double / long double).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01X4BQ833roTHs7CjAZfWYRo
@timosachsenberg
timosachsenberg force-pushed the claude/laughing-wozniak-t96825 branch from fa9e6dd to d4a0c34 Compare June 26, 2026 12:02

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/tests/class_tests/openms/source/String_test.cpp`:
- Around line 145-152: The current StringUtils::toStr tests cover the restored
“1.0e±xx” formatting but do not explicitly verify single-digit exponent
zero-padding. Add a dedicated assertion in String_test.cpp, near the existing
scientific-notation cases in the StringUtils::toStr test block, that exercises a
value expected to normalize to an exponent like “e-03” so the padding path is
covered and a regression there will fail the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3495254f-fe8d-4b02-99c2-02f1409d72ee

📥 Commits

Reviewing files that changed from the base of the PR and between fa9e6dd and d4a0c34.

📒 Files selected for processing (2)
  • src/openms/source/DATASTRUCTURES/StringUtils.cpp
  • src/tests/class_tests/openms/source/String_test.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/source/DATASTRUCTURES/StringUtils.cpp

@timosachsenberg
timosachsenberg requested a review from cbielow June 26, 2026 14:04
@timosachsenberg
timosachsenberg merged commit 480d3eb into develop Jun 26, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the claude/laughing-wozniak-t96825 branch June 26, 2026 14:50
timosachsenberg added a commit that referenced this pull request Jun 27, 2026
Documents four PRs that landed on 2026-06-26 after the last CHANGELOG
update (#9667):

- #9668: fix platform-dependent float formatting in scientific notation
- #9669: feat(PIPECHO) cap SVM training-set size (max_training_points)
- #9670: fix SimpleSVM constant-predictor crashes in predict()/setup()
- #9672: perf PeptideAndProteinQuant O(1) sample-ID lookup (fixes IsobaricWorkflow hang)

GitHub Actions version bump (#9673) carries no CHANGELOG entry per the
PR author's own checklist.


Claude-Session: https://claude.ai/code/session_01JxivySW6RCM1tKbU8H6bfj

Co-authored-by: Claude <[email protected]>
@jonasscheid jonasscheid mentioned this pull request Oct 13, 2026
4 tasks done
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.

2 participants