Skip to content

Replace crashing round_to/floor_to/ceiling_to with _try variants - #10360

Merged
lukewilliamboswell merged 3 commits into
roc-lang:mainfrom
dmisiuk:builtin-round-try
Jul 26, 2026
Merged

Replace crashing round_to/floor_to/ceiling_to with _try variants#10360
lukewilliamboswell merged 3 commits into
roc-lang:mainfrom
dmisiuk:builtin-round-try

Conversation

@dmisiuk

@dmisiuk dmisiuk commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Replaces the crashing round_to_* / floor_to_* / ceiling_to_* float→int conversions (all routed through out_of_range_or_crash) with fallible _try variants returning Try(Int, [OutOfRange]), and drops the now-unused helper.

Per discussion in #contributing ("basic-cli good first issues"): rounding conversions shouldn't crash, and since the conversion already goes through a conditional, the honest total answer is _try — the _wrap variants stay as the explicit total escape hatch. Confirmed by @rtfeldman: one PR for all three families, naming <op>_to_<int>_try.

Scope: 90 fns — {round,floor,ceiling}to{i8,i16,i32,i64,i128,u8,u16,u32,u64,u128} × {Dec, F32, F64}.

Notes:

  • Pure Roc — no new low-level ops or backend changes; bodies just drop the out_of_range_or_crash wrapper.
  • The out-of-range/NaN/inf path is now testable (it crashed before): added test/snapshots/repl/frac_round_to_try.md covering it, updated the eval_low_level_tests.zig cases and all doc-tests.

dmisiuk added 2 commits July 24, 2026 23:12
The float-to-int rounding conversions crashed on out-of-range, NaN, and
infinite input. Replace them with round_to_*_try / floor_to_*_try /
ceiling_to_*_try returning Try(Int, [OutOfRange]), and drop the now-unused
out_of_range_or_crash helper.
@dmisiuk
dmisiuk force-pushed the builtin-round-try branch from a3f013a to 3bca3c6 Compare July 24, 2026 21:16
rtfeldman
rtfeldman previously approved these changes Jul 24, 2026
@rtfeldman

Copy link
Copy Markdown
Contributor

Thanks @dmisiuk! 🎉

@lukewilliamboswell
lukewilliamboswell merged commit 5458e09 into roc-lang:main Jul 26, 2026
14 checks passed
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.

3 participants