Source context

Program Rust

body

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

206             return;207         }208         let mask = (1_u64 << shift) - 1;209         while read_index < self.num_digits {210             let new_digit = (n >> shift) as u8;211             n = (10 * (n & mask)) + self.digits[read_index] as u64;212             read_index += 1;213             self.digits[write_index] = new_digit;214             write_index += 1;215         }216         while n > 0 {217             let new_digit = (n >> shift) as u8;218             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
Lines209:8–215:9
Program versionOriginal program