Fix #109 int to float#124
Merged
osteele merged 4 commits intoNov 14, 2025
Merged
Conversation
…havior Fixes #109 Previously, arithmetic filters (minus, plus, times) always converted operands to float64, causing large integers to be displayed in scientific notation (e.g., 1.743096446e+09). This change implements type-aware arithmetic that: - Preserves integer types when both operands are integers - Returns integers for integer operations (matching Ruby Liquid) - Returns floats when at least one operand is a float - Prevents scientific notation for large integer results Example: {{ 1743096453 | minus: 7 }} Before: 1.743096446e+09 After: 1743096446 This aligns the Go implementation with Shopify's Ruby Liquid, where integer arithmetic preserves integer types.
…cerns The gosec linter (G115) flagged potential integer overflow when converting uint and uint64 to int64. To address this, removed these types from integer arithmetic support, aligning with the divided_by filter pattern. These types will now fall back to float arithmetic, which is safe and matches the existing pattern in the codebase.
Improved the integer type handling to properly support uint and uint64: - Added runtime overflow checks in isIntegerType() to verify uint/uint64 values fit within int64 range (<=math.MaxInt64) - Values in range are treated as integers and preserve integer types - Values out of range gracefully fall back to float arithmetic - Added nolint directives with justification for gosec G115 warnings This maintains Shopify Ruby Liquid compatibility (Ruby has no unsigned types) while safely handling Go's uint/uint64 types that users might pass as template bindings. Example behavior: - uint(1000) | minus: 1 → 999 (integer) - uint64(MaxInt64) | minus: 1 → 9223372036854775806 (integer) - uint64(MaxInt64+1) | minus: 1 → 9.223372036854776e+18 (float) Fixes lint failures while preserving the fix for issue #109.
Added comprehensive test cases to verify that uint and uint64 types are properly handled in arithmetic operations: - Tests for uint type with plus, minus, and times operations - Tests for uint64 type with plus, minus, and times operations - All tests verify that values within int64 range preserve integer type This ensures the overflow-safe handling from commit 1e0783c is working correctly and prevents regressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #109
Previously, arithmetic filters (minus, plus, times) always converted operands to float64, causing large integers to be displayed in scientific notation (e.g., 1.743096446e+09).
This change implements type-aware arithmetic that:
Example:
{{ 1743096453 | minus: 7 }} Before: 1.743096446e+09 After: 1743096446
This aligns the Go implementation with Shopify's Ruby Liquid, where integer arithmetic preserves integer types.
Checklist
make testpasses.make lintpasses.