Program Rust
body
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
178 let mut write_index = 0;179 let mut n = 0_u64;180 let mut all_zero = false;181 while (n >> shift) == 0 && !all_zero {182 if read_index < self.num_digits {183 n = (10 * n) + self.digits[read_index] as u64;184 read_index += 1;185 } else if n == 0 {186 // The source returns here from inside the loop. Recording the187 // condition and returning immediately after the loop executes188 // no intervening operation and preserves the unchanged value.189 all_zero = true;190 } else {191 while (n >> shift) == 0 {192 n *= 10;193 read_index += 1;194 }195 break;196 }197 }198 if all_zero {199 return;200 }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 | 181:8–197:9 |
| Program version | Revised program |