Repository navigation
Fix platform-dependent float formatting in scientific notation (macOS CI) - #9668
Conversation
|
@timosachsenberg The following names might be missing from the
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 |
📝 WalkthroughWalkthrough
ChangesScientific notation formatting
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 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
fa9e6dd to
d4a0c34
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/openms/source/DATASTRUCTURES/StringUtils.cppsrc/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
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]>
Root Cause
The nightly CI
TOPP_OpenNuXL_5_out1test 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_charsfor float-to-string conversion. The reference fileOpenNuXL_5_output.idXMLwas 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 value9.497386403381825e-03, Apple libc++ produces9.497386403381820e-03(trailing zero at position 15), which after trailing-zero trimming becomes9.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_charsto 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-3instead ofe-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:
OpenNuXL_5_output.idXML(including the problematic9.497386403381825e-03) produce strings of the same length as the reference when using shortest round-trip....825→...824) is within FuzzyDiff'sratio=1.01tolerance.All FuzzyDiff-safe: YESNo reference file changes are needed.
Testing
TOPP_OpenNuXL_5_out1should pass on macOS 15 ARM64 after this fixGenerated by Claude Code
Summary by CodeRabbit
e-3→e-03).