Skip to content

Arithmetic operators#8

Merged
jg-rp merged 3 commits intomainfrom
arithmetic-operators
May 16, 2025
Merged

Arithmetic operators#8
jg-rp merged 3 commits intomainfrom
arithmetic-operators

Conversation

@jg-rp
Copy link
Copy Markdown
Owner

@jg-rp jg-rp commented May 15, 2025

This PR adds support for arithmetic operators +, -, *, /, % and **.

These operators are disabled by default. Enable them by passing arithmetic_operators: true when constructing a new Liquid2::Environment.

By default, arithmetic operators follow the same semantics as their filter equivalents and follow the usual operator precedence rules. I intend to add an option to change / and divide_by to not do integer division, and enable // and floor_divide_by. This will probably be done in a different pull request.

Yet another option to return undefined or infinity instead of raising a ZeroDivisionError or LiquidTypeError when dividing by zero might be good too.

@jg-rp jg-rp marked this pull request as ready for review May 15, 2025 08:14
@jg-rp jg-rp added the feature label May 15, 2025
@jg-rp jg-rp merged commit 69635d1 into main May 16, 2025
8 checks passed
@jg-rp jg-rp deleted the arithmetic-operators branch May 16, 2025 07:13
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.

1 participant