Program Rust
body
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
61 fn try_parse_19digits(s_ref: &mut &[u8], x: &mut u64) {62 let mut s = *s_ref;63 64 while *x < MIN_19DIGIT_INT {65 if let Some((c, s_next)) = s.split_first() {66 let digit = c.wrapping_sub(b'0');67 68 if digit < 10 {69 *x = (*x * 10) + digit as u64; // no overflows here70 s = s_next;71 } else {72 break;73 }74 } else {75 break;76 }77 }78 79 *s_ref = s;80 }Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
@[rust_loop_body]
def num.imp.dec2flt.parse.try_parse_19digits_loop.body
(x : Std.U64) (s : Slice Std.U8) :
Result (ControlFlow (Std.U64 × (Slice Std.U8)) ((Slice Std.U8) × Std.U64))
:= do
if x < num.imp.dec2flt.parse.MIN_19DIGIT_INT
then
let o ← core.slice.Slice.split_first s
match o with
| none => ok (done (s, x))
| some p =>
let (c, s_next) := p
let digit ← lift (core.num.U8.wrapping_sub c 48#u8)
if digit < 10#u8
then
let i ← x * 10#u64
let i1 ← lift (UScalar.cast .U64 digit)
let x1 ← i + i1
ok (cont (x1, s_next))
else ok (done (s, x))
else ok (done (s, x))Other extracted objects at this span
Source details
| Declaration | num.imp.dec2flt.parse.try_parse_19digits_loop.body |
|---|---|
| File | num/imp/../../dec2flt/parse.rs |
| Lines | 64:4–77:5 |
| Program version | Original program |