Source context

Program Rust

body

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

135         let mut write_index = self.num_digits + num_new_digits;136         let mut n = 0_u64;137 138         while read_index != 0 {139             read_index -= 1;140             write_index -= 1;141             n += (self.digits[read_index] as u64) << shift;142             let quotient = n / 10;143             let remainder = n - (10 * quotient);144             if write_index < Self::MAX_DIGITS {145                 self.digits[write_index] = remainder as u8;146             } else if remainder > 0 {147                 self.truncated = true;148             }149             n = quotient;150         }151 152         while n > 0 {153             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

MAX_DIGITS · Program Rust

Other extracted objects at this span

num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop0

Source details
Declarationnum.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop0.body
Filenum/imp/../../dec2flt/decimal_seq.rs
Lines138:8–150:9
Program versionPreparation 2