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

Fix parsing of negative fractional fixed-point strings #935

Merged
merged 2 commits into from
May 25, 2021
Merged

Fix parsing of negative fractional fixed-point strings #935

merged 2 commits into from
May 25, 2021

Conversation

mikeylemmon
Copy link

@mikeylemmon mikeylemmon commented May 23, 2021

Closes #934

Description

A bug in parseFixedPoint was causing the function to return positive values for strings like "-0.1" because it was only checking if the integer component is less than zero. This PR fixes the bug by ensuring the return value is negative if the string begins with '-'.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

A bug in `parseFixedPoint` was causing the function to return positive
values for strings like "-0.1" because it was only checking if the
integer component is less than zero. This commit fixes the bug by
ensuring the return value is negative if the string begins with '-'.
@codecov-commenter
Copy link

codecov-commenter commented May 23, 2021

Codecov Report

Merging #935 (040ad7d) into master (2d95036) will decrease coverage by 0.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #935      +/-   ##
==========================================
- Coverage   74.19%   74.05%   -0.14%     
==========================================
  Files         267      269       +2     
  Lines       32993    33074      +81     
==========================================
+ Hits        24479    24494      +15     
- Misses       7386     7452      +66     
  Partials     1128     1128              
Flag Coverage Δ
unittests 74.05% <100.00%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
fixedpoint/parse.go 93.42% <100.00%> (-0.09%) ⬇️
runtime/ast/transaction_declaration.go 61.11% <0.00%> (-12.23%) ⬇️
runtime/ast/statement.go 72.89% <0.00%> (-8.87%) ⬇️
runtime/ast/variable_declaration.go 70.37% <0.00%> (-8.80%) ⬇️
runtime/ast/block.go 87.50% <0.00%> (-7.96%) ⬇️
runtime/ast/interface.go 81.25% <0.00%> (-5.42%) ⬇️
runtime/ast/pragma.go 68.75% <0.00%> (-4.59%) ⬇️
runtime/ast/expression.go 66.74% <0.00%> (-3.33%) ⬇️
runtime/ast/function_declaration.go 63.26% <0.00%> (-2.70%) ⬇️
runtime/ast/program.go 71.92% <0.00%> (-1.29%) ⬇️
... and 11 more

Continue to review full report at Codecov.

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

@Kay-Zee
Copy link
Member

Kay-Zee commented May 23, 2021

Repro for the problem. https://play.golang.org/p/URyXIX-HTU_S

@turbolent
Copy link
Member

@mikeylemmon Thank you for reporting this bug and also fixing it! 👍

I'll add some tests.

@turbolent turbolent requested a review from SupunS May 23, 2021 17:18
@turbolent turbolent self-assigned this May 23, 2021
@turbolent turbolent merged commit a0332c6 into onflow:master May 25, 2021
@mikeylemmon mikeylemmon deleted the fix-neg-fraction branch May 26, 2021 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Negative fractional fixed-point string values (e.g. "-0.1") are parsed as positive
4 participants