Source context

Program Rust

body

This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.

207             return;208         }209         let mask = (1_u64 << shift) - 1;210         while read_index < self.num_digits {211             let new_digit = (n >> shift) as u8;212             n = (10 * (n & mask)) + self.digits[read_index] as u64;213             read_index += 1;214             self.digits[write_index] = new_digit;215             write_index += 1;216         }217         while n > 0 {218             let new_digit = (n >> shift) as u8;219             n = 10 * (n & mask);

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1.body
  (i : Std.Usize) (shift : Std.Usize) (mask : Std.U64)
  (a : Array Std.U8 768#usize) (read_index : Std.Usize)
  (write_index : Std.Usize) (n : Std.U64) :
  Result (ControlFlow ((Array Std.U8 768#usize) × Std.Usize × Std.Usize ×
    Std.U64) ((Array Std.U8 768#usize) × Std.Usize × Std.U64))
  := do
  if read_index < i
  then
    let i1 ← n >>> shift
    let new_digit ← lift (UScalar.cast .U8 i1)
    let i2 ← lift (n &&& mask)
    let i3 ← 10#u64 * i2
    let i4 ← Array.index_usize a read_index
    let i5 ← lift (UScalar.cast .U64 i4)
    let n1 ← i3 + i5
    let read_index1 ← read_index + 1#usize
    let a1 ← Array.update a write_index new_digit
    let write_index1 ← write_index + 1#usize
    ok (cont (a1, read_index1, write_index1, n1))
  else ok (done (a, write_index, n))
Other extracted objects at this span

num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1

Source details
Declarationnum.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1.body
Filenum/imp/../../dec2flt/decimal_seq.rs
Lines210:8–216:9
Program versionRevised program