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 division remainder operator (%) #272

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/expression_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ InternalValue BinaryExpression::Evaluate(RenderContext& context)
case jinja2::BinaryExpression::Minus:
case jinja2::BinaryExpression::Mul:
case jinja2::BinaryExpression::Div:
case jinja2::BinaryExpression::DivReminder:
case jinja2::BinaryExpression::DivRemainder:
case jinja2::BinaryExpression::DivInteger:
case jinja2::BinaryExpression::Pow:
result = Apply2<visitors::BinaryMathOperation>(leftVal, rightVal, m_oper);
Expand Down
2 changes: 1 addition & 1 deletion src/expression_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class BinaryExpression : public Expression
Minus,
Mul,
Div,
DivReminder,
DivRemainder,
DivInteger,
Pow,
StringConcat
Expand Down
2 changes: 1 addition & 1 deletion src/expression_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ ExpressionParser::ParseResult<ExpressionEvaluatorPtr<Expression>> ExpressionPars
operation = BinaryExpression::DivInteger;
break;
case '%':
operation = BinaryExpression::DivReminder;
operation = BinaryExpression::DivRemainder;
break;
default:
lexer.ReturnToken();
Expand Down
6 changes: 3 additions & 3 deletions src/value_visitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ struct BinaryMathOperation : BaseVisitor<>
case jinja2::BinaryExpression::Div:
result = left / right;
break;
case jinja2::BinaryExpression::DivReminder:
result = std::remainder(left, right);
case jinja2::BinaryExpression::DivRemainder:
result = std::fmod(left, right);
break;
case jinja2::BinaryExpression::DivInteger:
{
Expand Down Expand Up @@ -607,7 +607,7 @@ struct BinaryMathOperation : BaseVisitor<>
result = left / right;
break;
case jinja2::BinaryExpression::Div:
case jinja2::BinaryExpression::DivReminder:
case jinja2::BinaryExpression::DivRemainder:
case jinja2::BinaryExpression::Pow:
result = this->operator ()(static_cast<double>(left), static_cast<double>(right));
break;
Expand Down
2 changes: 2 additions & 0 deletions test/expressions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ R"(
{{ 7 / 3}}
{{ 7 // 3 }}
{{ 7 % intValue }}
{{ 11 % 7 }}
{{ 3 ** 4 }}
{{ 10 ** -2 }}
{{ 10/10 + 2*5 }}
Expand Down Expand Up @@ -48,6 +49,7 @@ R"(
2.3333333
2
1
4
81
0.01
11
Expand Down
Loading