Format: trimming zeros in a fraction changes a timer's duration #286

Closed
opened 2026-11-26 19:39:09 +01:00 by abiwab · 0 comments
Owner

Found by the fuzz (format-preserves-meaning … at $.metrics.activeBreakdown[], seed 3993218965, index 29835 on dev/1.6), present on main and dev/1.6.

Rule 4 (trailing decimal zeros) also trims a term of a fraction. The compiler reads neither 1.0/5 nor 1/5.0 as a duration, while it does read 1/5, so gram format changes a timer:

  • ~{1.0/5 min}: INVALID_DURATION (default 2 min) → ~{1/5 min}: 0.2 min.
  • ~{1/5.0 min / 500.0 g @&b} (proportional timer, the number range is the whole durationRaw): default duration → ~{1/5 min / 500 g @&b}: 0.04 min.

Fix: never trim the zeros of a number glued to a / (a fraction's term). A ratio's / is never inside one number's range, so its terms are still trimmed ({1.50 / 100.0 g @&b} → {1.5 / 100 g @&b}). Cosmetic cost: {1.50/2 g} is no longer rewritten {1.5/2 g}.

Related, not in scope: the parser reads {1.5/2} as a fraction (0.75) for an ingredient, while kitchen's timer duration rejects ~{1.5/2 min} (INVALID_DURATION). Whether a decimal numerator is a valid fraction should be one answer across parser and kitchen.

Found by the fuzz (`format-preserves-meaning … at $.metrics.activeBreakdown[]`, seed 3993218965, index 29835 on `dev/1.6`), present on `main` and `dev/1.6`. Rule 4 (trailing decimal zeros) also trims a term of a fraction. The compiler reads neither `1.0/5` nor `1/5.0` as a duration, while it does read `1/5`, so `gram format` changes a timer: - `~{1.0/5 min}`: `INVALID_DURATION` (default 2 min) → `~{1/5 min}`: 0.2 min. - `~{1/5.0 min / 500.0 g @&b}` (proportional timer, the number range is the whole `durationRaw`): default duration → `~{1/5 min / 500 g @&b}`: 0.04 min. Fix: never trim the zeros of a number glued to a `/` (a fraction's term). A ratio's ` / ` is never inside one number's range, so its terms are still trimmed (`{1.50 / 100.0 g @&b}` → `{1.5 / 100 g @&b}`). Cosmetic cost: `{1.50/2 g}` is no longer rewritten `{1.5/2 g}`. Related, not in scope: the parser reads `{1.5/2}` as a fraction (0.75) for an ingredient, while kitchen's timer duration rejects `~{1.5/2 min}` (`INVALID_DURATION`). Whether a decimal numerator is a valid fraction should be one answer across parser and kitchen.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gram-lang/gram#286
No description provided.