Program Rust
body
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
177 let mut write_index = 0;178 let mut n = 0_u64;179 let mut all_zero = false;180 while (n >> shift) == 0 && !all_zero {181 if read_index < self.num_digits {182 n = (10 * n) + self.digits[read_index] as u64;183 read_index += 1;184 } else if n == 0 {185 // The source returns here from inside the loop. Recording the186 // condition and returning immediately after the loop executes187 // no intervening operation and preserves the unchanged value.188 all_zero = true;189 } else {190 while (n >> shift) == 0 {191 n *= 10;192 read_index += 1;193 }194 break;195 }196 }197 if all_zero {198 return;199 }Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0.body
(self : num.imp.dec2flt.decimal_seq.DecimalSeq) (shift : Std.Usize)
(read_index : Std.Usize) (n : Std.U64) (all_zero : Bool) :
Result (ControlFlow (Std.Usize × Std.U64 × Bool)
(num.imp.dec2flt.decimal_seq.DecimalSeq × Std.Usize × Std.U64 × Bool))
:= do
let i ← n >>> shift
if i = 0#u64
then
if all_zero
then ok (done (self, read_index, n, true))
else
if read_index < self.num_digits
then
let i1 ← 10#u64 * n
let i2 ← Array.index_usize self.digits read_index
let i3 ← lift (UScalar.cast .U64 i2)
let n1 ← i1 + i3
let read_index1 ← read_index + 1#usize
ok (cont (read_index1, n1, false))
else
if n = 0#u64
then ok (cont (read_index, n, true))
else
let (read_index1, n1) ←
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0_loop0
shift read_index n
ok (done (self, read_index1, n1, false))
else ok (done (self, read_index, n, all_zero))Other extracted objects at this span
Source details
| Declaration | num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0.body |
|---|---|
| File | num/imp/../../dec2flt/decimal_seq.rs |
| Lines | 180:8–196:9 |
| Program version | Preparation 2 |