Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing fast float stod conversion according to ST_Number schema specification #339

Merged
merged 5 commits into from
Jan 31, 2024

Conversation

gangatp
Copy link
Collaborator

@gangatp gangatp commented Jan 30, 2024

  • Allowing leading + sign

  • Not allowing , separated values

    • example: for a comma separated value 123,456 . The result from from_chars will be result=123.0 and answer.ptr = ',456'

    auto answer = fast_float::from_chars(input.data(), input.data()+input.size(), result);
    if(answer.ec != std::errc()) {
    // check error
    }
    if(answer.ptr[0] == ',') {
    // unexpected delimiter
    }

Copy link

codecov bot commented Jan 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e77162c) 69.19% compared to head (324ed58) 69.20%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #339   +/-   ##
========================================
  Coverage    69.19%   69.20%           
========================================
  Files          271      271           
  Lines        28688    28691    +3     
========================================
+ Hits         19851    19855    +4     
+ Misses        8837     8836    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -149,4 +149,10 @@ namespace Lib3MF
auto reader = model->QueryReader("3mf");
ASSERT_SPECIFIC_THROW(reader->ReadFromFile(sTestFilesPath + "/Reader/" + "GEN-M-ADA-ITEM-TRANSFORM-0.3mf"), ELib3MFException);
}


TEST_F(Reader, IntegrationTestError) {
Copy link
Member

Choose a reason for hiding this comment

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

good idea to add a test there.

Please explain what the content of the file is and why it should fail.
Also please change the name to something meaningfull.

@@ -161,6 +161,10 @@ namespace NMR {
{
throw CNMRException(NMR_ERROR_EMPTYSTRINGTODOUBLECONVERSION);
}
else if (answer.ptr && answer.ptr[0] == ',') // Invalidate comma as decimal separator
{
throw CNMRException(NMR_ERROR_INVALIDSTRINGTODOUBLECONVERSION);
Copy link
Member

Choose a reason for hiding this comment

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

let's also add a test for that, please.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer that we do never add such style of code. While it is shorter, it is a landmine and who knows on what situation and platform (or little change by somebody) answer.ptr[0] is evaluated when answer.ptr == nullptr.

Making two if statements out of it is much easier to read and much safer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if(answer.ptr){
if(answer.ptr[0] == ','){
throw here
}
}

I can make this into two if statements for readability, but that would mean the same. Did you mean anything else?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's what I meant, yes :)

@martinweismann martinweismann merged commit 8ceec9c into develop Jan 31, 2024
24 checks passed
@martinweismann martinweismann deleted the gangatp/fixing_stod branch January 31, 2024 10:43
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