Skip to content

[FIX] Accept representable subnormals on affected toolchains - #10534

Closed
poshul wants to merge 3 commits into
developfrom
fix/stringutils-subnormal-parsing
Closed

poshul wants to merge 3 commits into
developfrom
fix/stringutils-subnormal-parsing

Conversation

@poshul

@poshul poshul commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Representable subnormal numbers such as 1e-40 and 2.17388884170148e-321 can be rejected by a standard library's floating-point std::from_chars implementation. This breaks StringUtils conversion and MRMFeatureSelector inputs on affected toolchains.

Reuse the existing locale-independent C parser when from_chars reports an out-of-range value. Finite subnormal results are accepted; overflow is still rejected. The existing libc++ fallback and ordinary conversions keep their behavior.

Validation: rebuilt the library and existing StringUtils/MRMFeatureSelector class tests in the Linux validation image; both pass. Both failed before this change on the same toolchain. Existing StringUtils tests already cover the affected float and double values, so no test files or targets are added.

This is a separate correctness prerequisite found while checking the staged NASE feature stack. It targets develop directly and contains only the previously validated portability fix from the preserved integration.

Final combined-stack verification with the independent subnormal parsing fix #10534: 2971 configured CTest cases passed (5 skipped), and 6647 Python cases passed (30 skipped). Linux Release configuration; optional GUI, ThermoRaw and opentims were disabled. These totals apply to the combined stack, alongside the per-topic checks above.

Summary by CodeRabbit

  • Bug Fixes

    • Floating-point parsing now correctly accepts representable subnormal values and converts values too small to round to a nonzero value into signed zero.
    • Fuzzy comparisons now handle subnormal values and underflow consistently. Overflow continues to be reported as an error.
  • Documentation

    • Clarified accepted whitespace, conversion errors, and token extraction behavior for floating-point conversion utilities.

@timosachsenberg timosachsenberg 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.

The approach looks right: removing the #ifdef is needed now that parseFloat calls fromCharsFloat on non-libc++ builds, and the fallback only runs on the error path. I reproduced the bug against GCC 11's libstdc++ runtime. Its strtod-based from_chars returns result_out_of_range for 1e-40 (float), 2.17388884170148e-321 and 4.9e-324. GCC 12+ accepts them, which is why CI (Ubuntu 24.04, macOS, MSVC) never saw it. Since OPENMS_MIN_GCC is 13, the affected setup is presumably Clang on an older system libstdc++ (Ubuntu 22.04, RHEL 9). Which image was this?

Before merge:

  1. Values too small for a subnormal now parse as 0 on all platforms. libstdc++ (GCC 13 too) returns result_out_of_range for e.g. 1e-400 (double) or 1e-50 (float). The fallback accepts ERANGE whenever the result is not inf, so toDouble("1e-400") changes from throwing ConversionError to returning 0.0 on Linux/Windows. That matches what libc++ already did, so it may be fine, but please state it and add a test, or reject ERANGE && value == 0 if you want the old behavior.
  2. FuzzyStringComparator.cpp (lines 125-220) is not updated. It holds a verbatim copy of these helpers with a "keep the two in sync" note, and still has the _LIBCPP_VERSION-only fallback. On the affected toolchain FuzzyDiff still won't parse subnormals as numbers, and the library and FuzzyDiff now disagree on underflow tokens.
  3. Some comments are now stale:
    • "All other standard libraries … use std::from_chars directly" (~L180)
    • "dispatching to std::from_chars or the libc++ fallback"
    • "std::from_chars only reports result_out_of_range on overflow", which is false for libstdc++

Generated by Claude Code

@timosachsenberg timosachsenberg 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.

Follow-up review of bb10ef29473f, confirming the two behavioral concerns in the earlier review.

A focused executable using the changed StringUtils implementation produced:

toDouble("1e-400") -> 0
toDouble("1e400") -> exception
toDouble("2.17388884170148e-321") -> 2.17389e-321
FuzzyStringComparator.compareStrings("1e-400", "0") -> false
  1. [P2] Parser synchronization: StringUtils.cpp:260–264 now retries out-of-range tokens, while src/testframework/source/CONCEPT/FuzzyStringComparator.cpp:215–220 still calls std::from_chars directly outside libc++. Its "keep the two in sync" contract is therefore broken, and the old-library subnormal problem remains in that path. The local probe above also demonstrates disagreement on an underflow token.
  2. Underflow policy: 1e-400 is not a representable subnormal. Returning zero may be intentional, but it broadens behavior beyond the PR title. Either reject underflow-to-zero or document and test its acceptance explicitly.

@poshul, can you confirm whether these are real issues to address here? Specifically, is accepting underflow-to-zero intentional, and should the FuzzyDiff parser be updated in this PR to maintain the shared numeric-token contract?

Validation was a focused build using existing supporting OpenMS libraries. The affected older libstdc++ runtime was not rerun in this follow-up; that part follows from the unchanged parser path and the earlier review's reproduction.

Review performed with Codex.

@poshul

poshul commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in 34f1273. Underflow to signed zero is intentional and is now documented and tested for float, double and token extraction. FuzzyStringComparator uses the same C-locale fallback, token grammar and overflow rejection. Seven class/TOPP checks pass.

The affected image is localhost/nase-validation:2026-10-11, exact ID 8570b6aa3b6dd817ba45c067dc9c62f0916afb317d80cd89ddc49c1555599314, based on manylinux_2_34_x86_64 / AlmaLinux 9.7. The compiler is GCC 14.2.1 (20250110, Red Hat 14.2.1-12), glibc 2.34; the probe loads /lib64/libstdc++.so.6. A standalone std::from_chars probe in that image returns result_out_of_range for both float 1e-40 and double 2.17388884170148e-321.

@timosachsenberg

Copy link
Copy Markdown
Contributor

one thing to consider:
comparison against small integers are exact with floating point values.
So it could cause strange side effects when something was != 0 before and becomes 0 now.
just a gut feeling ;)

@poshul

poshul commented Oct 12, 2026 via email

Copy link
Copy Markdown
Collaborator Author

@timosachsenberg

Copy link
Copy Markdown
Contributor

I guess it is fine. Just to keep in mind in case some strange bugs show up...

@timosachsenberg

Copy link
Copy Markdown
Contributor

maybe @cbielow has some opinion here

@poshul
poshul marked this pull request as ready for review October 12, 2026 11:23
@poshul
poshul enabled auto-merge (squash) October 12, 2026 11:23
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a13f7a4-b6a5-4cc7-b1d6-edbce91c1efd

📥 Commits

Reviewing files that changed from the base of the PR and between a5dfc94 and e14d743.


📒 Files selected for processing (5)
  • src/openms/include/OpenMS/DATASTRUCTURES/StringUtils.h
  • src/openms/source/DATASTRUCTURES/StringUtils.cpp
  • src/testframework/source/CONCEPT/FuzzyStringComparator.cpp
  • src/tests/class_tests/openms/source/FuzzyStringComparator_test.cpp
  • src/tests/class_tests/openms/source/StringUtils_test.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.



📝 Walkthrough

Walkthrough

StringUtils and FuzzyStringComparator now retry out-of-range floating-point parses through C-locale parsers. The changes accept representable subnormals and underflow to signed zero while retaining overflow errors. Documentation and tests cover parsing and token extraction behavior.

Changes

Subnormal parsing

Layer / File(s) Summary
StringUtils parsing and extraction
src/openms/include/OpenMS/DATASTRUCTURES/StringUtils.h, src/openms/source/DATASTRUCTURES/StringUtils.cpp, src/tests/class_tests/openms/source/StringUtils_test.cpp
Documentation describes accepted subnormals, signed-zero underflow, whitespace, and conversion errors. Parsing retries out-of-range results through the C-locale parser. Tests check signed zero and token consumption.
Fuzzy comparator parsing
src/testframework/source/CONCEPT/FuzzyStringComparator.cpp, src/tests/class_tests/openms/source/FuzzyStringComparator_test.cpp
The comparator uses C-locale helpers for out-of-range parsing. Tests cover subnormal equivalence, underflow to signed zero, and large values compared with zero.

Suggested reviewers: timosachsenberg


Priority: ➖ Normal

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e14d7

No actionable issue remains in the supplied review evidence; the change is mergeable after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 5 files. 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 and concisely describes the main change: accepting representable subnormal values on affected toolchains.
Linked Issues check Passed Issue #10534 requires fallback parsing when floating-point std::from_chars returns result_out_of_range, acceptance of representable subnormals, acceptance of signed underflow to zero, rejection of…
Out of Scope Changes check Passed The changed production files implement the issue #10534 parsing policy. The FuzzyStringComparator update keeps its duplicated numeric parser synchronized with StringUtils. The test changes verify su…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the numbers small,
Subnormals answer to the call.
When values sink to signed-zero ground,
Their signs remain, their paths are found.
The parser hops through each test run.

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

auto-merge was automatically disabled October 12, 2026 11:49

Pull request was closed

@cbielow

cbielow commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

a IMHO better alternative is to track down the code producing the subnormals and get rid of them.
Even with modern CPUs there should be a performance impact when handling them (Intel used to be notoriously bad, but it has improved).

i.e.
trap FE_UNDERFLOW in hardware and catch the resulting SIGFPE should tell you exactly where it happens (when running NASE) - see https://johnnysswlab.com/floating-point-error-handling-in-c-what-actually-works/

@timosachsenberg

Copy link
Copy Markdown
Contributor

Thanks!

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.

3 participants