Program Rust
body
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
236 let mut n_trailing_zeros = 0;237 let mut i = consumed_len;238 let mut scanning = true;239 while i != 0 && scanning {240 let c = start[i - 1];241 if c == b'0' || c == b'.' {242 i -= 1;243 if c == b'0' {244 n_trailing_zeros += 1;245 }246 } else {247 scanning = false;248 }249 }250 n_trailing_zeros251 }252 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 | 239:4–249:5 |
| Program version | Preparation 2 |