Replace crashing round_to/floor_to/ceiling_to with _try variants - #10360
Merged
Conversation
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
force-pushed
the
builtin-round-try
branch
from
July 24, 2026 21:16
a3f013a to
3bca3c6
Compare
rtfeldman
previously approved these changes
Jul 24, 2026
Contributor
|
Thanks @dmisiuk! 🎉 |
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.
Replaces the crashing
round_to_*/floor_to_*/ceiling_to_*float→int conversions (all routed throughout_of_range_or_crash) with fallible_tryvariants returningTry(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_wrapvariants 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:
out_of_range_or_crashwrapper.test/snapshots/repl/frac_round_to_try.mdcovering it, updated theeval_low_level_tests.zigcases and all doc-tests.