Skip to content

[refactor] Replace std::stof with parse_float - #368

Merged
antond-weta merged 2 commits into
AcademySoftwareFoundation:mainfrom
antond-weta:from_chars
Nov 10, 2026
Merged

antond-weta merged 2 commits into
AcademySoftwareFoundation:mainfrom
antond-weta:from_chars

Conversation

@antond-weta

Copy link
Copy Markdown
Contributor

Replace the throwing std::stof calls with the non-throwing rta::helpers::parse_float helper (based on std::from_chars) across spectral_data.cpp, exiftool.cpp, and the UsageTimer test. The helper lives in src/cpp/misc/helpers.{h,cpp} and is wired into the relevant CMakeLists.txt files. A non-numeric input now returns false instead of throwing, letting callers handle malformed input gracefully.

Assisted-by: nemotron-3.5-super-vl-free

Description

Tests

Checklist:

  • I have read the contribution guidelines.
  • I have read the Policy on AI Coding Assistants
    and if I used AI coding assistants, I have an Assisted-by: TOOL / MODEL
    line in the pull request description above.
  • I have updated the documentation, if applicable. (Check if there is no
    need to update the documentation, for example if this is a bug fix that
    doesn't change the API.)
  • I have ensured that the change is tested somewhere in the testsuite
    (adding new test cases if necessary).
  • My code follows the prevailing code style of this project. If I haven't
    already run clang-format before submitting, I definitely will look at the CI
    test that runs clang-format and fix anything that it highlights as being
    nonconforming.

Replace the throwing std::stof calls with the non-throwing
rta::helpers::parse_float helper (based on std::from_chars) across
spectral_data.cpp, exiftool.cpp, and the UsageTimer test. The helper
lives in src/cpp/misc/helpers.{h,cpp} and is wired into the relevant
CMakeLists.txt files. A non-numeric input now returns false instead of
throwing, letting callers handle malformed input gracefully.

Assisted-by: nemotron-3.5-super-vl-free
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
@codecov-commenter

codecov-commenter commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.96%. Comparing base (689412b) to head (8db4e58).

Files with missing lines Patch % Lines
src/cpp/rawtoaces_core/spectral_data.cpp 42.85% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #368      +/-   ##
==========================================
- Coverage   92.04%   91.96%   -0.08%     
==========================================
  Files          17       18       +1     
  Lines        3959     3970      +11     
  Branches      591      597       +6     
==========================================
+ Hits         3644     3651       +7     
- Misses        315      319       +4     
Files with missing lines Coverage Δ
src/cpp/misc/helpers.cpp 100.00% <100.00%> (ø)
src/cpp/rawtoaces_util/exiftool.cpp 98.62% <100.00%> (+0.01%) ⬆️
src/cpp/rawtoaces_core/spectral_data.cpp 98.08% <42.85%> (-1.92%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 689412b...8db4e58. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

{
*error_message = "Error: Failed to parse wavelength '" +
bin_wavelength + "' in " + path + ".";
}

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.

you reckon this error handling and error adding can be integrated into helper ... I guess not, you'd need to pass error message in as a ref. and all that. ignore me.

Comment thread src/cpp/misc/helpers.cpp

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.

/nit I feel like now when we have opened that flood gate of "util" or "helper" place we can drop here bunch stuff from other places.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Which is a good thing, right?
rawtoaces_util is a public target containing image conversion functionality (poorly named in my opinion). The whole reason for adding helpers was that it's not util.

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.

Which is a good thing, right?
yeah. I meant it as a good think. Though, util and helper are all similar in my mind. Anyway, good. Let's move some more here.

Add a test_parse_float unit test to Test_Misc covering valid decimal,
integer, negative, and prefix-parsing inputs, plus non-numeric inputs
that must return false without throwing. Wire src/cpp/misc/helpers.{h,cpp}
into the Test_Misc target so rta::helpers::parse_float is available.

Assisted-by: nemotron-3.5-super-vl-free
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
@antond-weta
antond-weta merged commit c907962 into AcademySoftwareFoundation:main Nov 10, 2026
26 checks passed
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