Source context

Program Rust

body

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

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);220             if write_index < Self::MAX_DIGITS {221                 self.digits[write_index] = new_digit;222                 write_index += 1;223             } else if new_digit > 0 {224                 self.truncated = true;225             }226         }227         self.num_digits = write_index;228         self.trim();229     }

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body
  (shift : Std.Usize) (mask : Std.U64) (b : Bool) (a : Array Std.U8 768#usize)
  (write_index : Std.Usize) (n : Std.U64) :
  Result (ControlFlow (Bool × (Array Std.U8 768#usize) × Std.Usize ×
    Std.U64) (Bool × (Array Std.U8 768#usize) × Std.Usize))
  := do
  if n > 0#u64
  then
    let i ← n >>> shift
    let new_digit ← lift (UScalar.cast .U8 i)
    let i1 ← lift (n &&& mask)
    let n1 ← 10#u64 * i1
    if write_index < num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
    then
      let a1 ← Array.update a write_index new_digit
      let write_index1 ← write_index + 1#usize
      ok (cont (b, a1, write_index1, n1))
    else
      if new_digit > 0#u8
      then ok (cont (true, a, write_index, n1))
      else ok (cont (b, a, write_index, n1))
  else ok (done (b, a, write_index))
Operations used here

MAX_DIGITS · Program Rust

Other extracted objects at this span

num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2

Source details
Declarationnum.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body
Filenum/imp/../../dec2flt/decimal_seq.rs
Lines217:8–226:9
Program versionRevised program