Program Rust
body
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
136 let mut write_index = self.num_digits + num_new_digits;137 let mut n = 0_u64;138 139 while read_index != 0 {140 read_index -= 1;141 write_index -= 1;142 n += (self.digits[read_index] as u64) << shift;143 let quotient = n / 10;144 let remainder = n - (10 * quotient);145 if write_index < Self::MAX_DIGITS {146 self.digits[write_index] = remainder as u8;147 } else if remainder > 0 {148 self.truncated = true;149 }150 n = quotient;151 }152 153 while n > 0 {154 write_index -= 1;Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop0.body
(shift : Std.Usize) (b : Bool) (a : Array Std.U8 768#usize)
(read_index : Std.Usize) (write_index : Std.Usize) (n : Std.U64) :
Result (ControlFlow (Bool × (Array Std.U8 768#usize) × Std.Usize ×
Std.Usize × Std.U64) (Bool × (Array Std.U8 768#usize) × Std.Usize ×
Std.U64))
:= do
if read_index != 0#usize
then
let read_index1 ← read_index - 1#usize
let write_index1 ← write_index - 1#usize
let i ← Array.index_usize a read_index1
let i1 ← lift (UScalar.cast .U64 i)
let i2 ← i1 <<< shift
let n1 ← n + i2
let quotient ← n1 / 10#u64
let i3 ← 10#u64 * quotient
let remainder ← n1 - i3
if write_index1 < num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
then
let i4 ← lift (UScalar.cast .U8 remainder)
let a1 ← Array.update a write_index1 i4
ok (cont (b, a1, read_index1, write_index1, quotient))
else
if remainder > 0#u64
then ok (cont (true, a, read_index1, write_index1, quotient))
else ok (cont (b, a, read_index1, write_index1, quotient))
else ok (done (b, a, write_index, n))Operations used here
Other extracted objects at this span
Source details
| Declaration | num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop0.body |
|---|---|
| File | num/imp/../../dec2flt/decimal_seq.rs |
| Lines | 139:8–151:9 |
| Program version | Revised program |