Source context

Program Rust

body

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

150             n = quotient;151         }152 153         while n > 0 {154             write_index -= 1;155             let quotient = n / 10;156             let remainder = n - (10 * quotient);157             if write_index < Self::MAX_DIGITS {158                 self.digits[write_index] = remainder as u8;159             } else if remainder > 0 {160                 self.truncated = true;161             }162             n = quotient;163         }164 165         self.num_digits += num_new_digits;166 

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop1.body
  (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)))
  := do
  if n > 0#u64
  then
    let write_index1 ← write_index - 1#usize
    let quotient ← n / 10#u64
    let i ← 10#u64 * quotient
    let remainder ← n - i
    if write_index1 < num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
    then
      let i1 ← lift (UScalar.cast .U8 remainder)
      let a1 ← Array.update a write_index1 i1
      ok (cont (b, a1, write_index1, quotient))
    else
      if remainder > 0#u64
      then ok (cont (true, a, write_index1, quotient))
      else ok (cont (b, a, write_index1, quotient))
  else ok (done (b, a))
Operations used here

MAX_DIGITS · Program Rust

Other extracted objects at this span

num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop1

Source details
Declarationnum.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop1.body
Filenum/imp/../../dec2flt/decimal_seq.rs
Lines153:8–163:9
Program versionRevised program