Program Rust
body
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
86 fn adjust_many_digit_count(start: &[u8], mut n_digits: isize) -> isize {87 let mut scan_index = 0;88 let mut scanning = true;89 while scan_index < start.len() && scanning {90 let c = start[scan_index];91 if c == b'.' || c == b'0' {92 n_digits -= c.saturating_sub(b'0' - 1) as isize;93 scan_index += 1;94 } else {95 scanning = false;96 }97 }98 n_digits99 }100 Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
@[rust_loop_body]
def num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
(start : Slice Std.U8) (n_digits : Std.Isize) (scan_index : Std.Usize)
(scanning : Bool) :
Result (ControlFlow (Std.Isize × Std.Usize × Bool) Std.Isize)
:= do
let i := Slice.len start
if scan_index < i
then
if scanning
then
let c ← Slice.index_usize start scan_index
if c = 46#u8
then
let i1 ← 48#u8 - 1#u8
let i2 ← lift (core.num.U8.saturating_sub c i1)
let i3 ← lift (UScalar.hcast .Isize i2)
let n_digits1 ← n_digits - i3
let scan_index1 ← scan_index + 1#usize
ok (cont (n_digits1, scan_index1, true))
else
if c = 48#u8
then
let i1 ← 48#u8 - 1#u8
let i2 ← lift (core.num.U8.saturating_sub c i1)
let i3 ← lift (UScalar.hcast .Isize i2)
let n_digits1 ← n_digits - i3
let scan_index1 ← scan_index + 1#usize
ok (cont (n_digits1, scan_index1, true))
else ok (cont (n_digits, scan_index, false))
else ok (done n_digits)
else ok (done n_digits)Other extracted objects at this span
Source details
| Declaration | num.imp.dec2flt.parse.adjust_many_digit_count_loop.body |
|---|---|
| File | num/imp/../../dec2flt/parse.rs |
| Lines | 89:4–97:5 |
| Program version | Revised program |