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

Plus, minus and times crossing 32 to 64 bit boundary #488

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

daviburg
Copy link
Member

@daviburg daviburg commented May 9, 2022

Handle integer numbers beyond the range of 32 bit integer but still within 64 bit integer range.

Fixes #483

@daviburg daviburg requested a review from microalps May 9, 2022 01:27
@daviburg daviburg self-assigned this May 9, 2022
@codecov
Copy link

codecov bot commented May 9, 2022

Codecov Report

Merging #488 (ce4cdac) into master (a00dc34) will decrease coverage by 0.25%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #488      +/-   ##
==========================================
- Coverage   87.53%   87.28%   -0.26%     
==========================================
  Files          69       69              
  Lines        2688     2697       +9     
  Branches      639      639              
==========================================
+ Hits         2353     2354       +1     
- Misses        212      213       +1     
- Partials      123      130       +7     
Impacted Files Coverage Δ
src/DotLiquid/StandardFilters.cs 93.22% <100.00%> (-0.41%) ⬇️
src/DotLiquid/Util/ListExtensionMethods.cs 62.50% <0.00%> (-6.25%) ⬇️
src/DotLiquid/FileSystems/EmbeddedFileSystem.cs 60.00% <0.00%> (-4.00%) ⬇️
src/DotLiquid/RenderParameters.cs 89.13% <0.00%> (-2.18%) ⬇️
src/DotLiquid/Tokenizer.cs 93.16% <0.00%> (-1.71%) ⬇️
src/DotLiquid/Drop.cs 70.73% <0.00%> (-1.22%) ⬇️
src/DotLiquid/Tags/For.cs 94.06% <0.00%> (-0.85%) ⬇️
src/DotLiquid/Util/ObjectExtensionMethods.cs 72.91% <0.00%> (ø)
src/DotLiquid/Util/ExpressionUtility.cs 100.00% <0.00%> (+2.17%) ⬆️

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 a00dc34...ce4cdac. Read the comment docs.

{
TestPlusNumericBoundaryByContext(_contextV20);
TestPlusNumericBoundaryByContext(_contextV21);
Helper.AssertTemplateResult(expected: "2147483648", template: "{{ '2147483647' | plus: 1 }}", syntax: _contextV21.SyntaxCompatibilityLevel);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we comment that this tests a string which is supported in Syntax 2.1? Should we also test a string as a local variable?

catch (OverflowException) when (input is int)
{
return DoMathsOperation(context, Convert.ToInt64(input), operand, Expression.MultiplyChecked);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what about divide by fraction? e.g. 2147483647 / 0.5 might result in an overflow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should convert to a floating point hence range is different.

? string.Concat(input, operand)
: DoMathsOperation(context, input, operand, Expression.AddChecked);
}
catch (OverflowException) when (input is int)
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't uint also have a boundary? and smaller integer values, like short? Additionally, Ruby implementation supports adding 1 to decimal max without losing precision.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried bytes and short, they worked fine without modification, I can add a few tests to demonstrate it. I didn't try uint.

Copy link
Member Author

Choose a reason for hiding this comment

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

BigInteger is out of scope for a bug fix, that support would be a feature in itself.

syntax: context.SyntaxCompatibilityLevel);

// NOTE(David Burg): We don't have support for BigInteger as this time.
Helper.AssertTemplateResult(
Copy link
Member Author

Choose a reason for hiding this comment

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

todo: also add tests demonstrating that byte max, short max work already, but double range limit cannot be extended beyond current overflow.

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.

Math Operations Don't Fully Handle Big Numbers
2 participants