Program Rust
body
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
237 let mut n_trailing_zeros = 0;238 let mut i = consumed_len;239 let mut scanning = true;240 while i != 0 && scanning {241 let c = start[i - 1];242 if c == b'0' || c == b'.' {243 i -= 1;244 if c == b'0' {245 n_trailing_zeros += 1;246 }247 } else {248 scanning = false;249 }250 }251 n_trailing_zeros252 }253 Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.count_trailing_zeros_loop.body
(start : Slice Std.U8) (n_trailing_zeros : Std.Usize) (i : Std.Usize)
(scanning : Bool) :
Result (ControlFlow (Std.Usize × Std.Usize × Bool) Std.Usize)
:= do
if i != 0#usize
then
if scanning
then
let i1 ← i - 1#usize
let c ← Slice.index_usize start i1
if c = 48#u8
then
if c = 48#u8
then
let n_trailing_zeros1 ← n_trailing_zeros + 1#usize
ok (cont (n_trailing_zeros1, i1, true))
else ok (cont (n_trailing_zeros, i1, true))
else
if c = 46#u8
then
if c = 48#u8
then
let n_trailing_zeros1 ← n_trailing_zeros + 1#usize
ok (cont (n_trailing_zeros1, i1, true))
else ok (cont (n_trailing_zeros, i1, true))
else ok (cont (n_trailing_zeros, i, false))
else ok (done n_trailing_zeros)
else ok (done n_trailing_zeros)Other extracted objects at this span
Source details
| Declaration | num.imp.dec2flt.decimal_seq.count_trailing_zeros_loop.body |
|---|---|
| File | num/imp/../../dec2flt/decimal_seq.rs |
| Lines | 240:4–250:5 |
| Program version | Revised program |