Source context

Program Rust

try_add_digit

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

71     // FIXME(tgross35): it may be better for this to return an option72     // FIXME(tgross35): incrementing the digit counter even if we don't push anything73     // seems incorrect.74     pub(super) fn try_add_digit(&mut self, digit: u8) {75         if self.num_digits < Self::MAX_DIGITS {76             self.digits[self.num_digits] = digit;77         }78         self.num_digits += 1;79     }80 81     /// Trim trailing zeros from the buffer.82     // FIXME(tgross35): this could be `.rev().position()` if perf is okay

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

def num.imp.dec2flt.decimal_seq.DecimalSeq.try_add_digit
  (self : num.imp.dec2flt.decimal_seq.DecimalSeq) (digit : Std.U8) :
  Result num.imp.dec2flt.decimal_seq.DecimalSeq
  := do
  let a ←
    if self.num_digits < num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
    then Array.update self.digits self.num_digits digit
    else ok self.digits
  let i ← self.num_digits + 1#usize
  ok { self with num_digits := i, digits := a }
Operations used here

DecimalSeq · Program Rust

MAX_DIGITS · Program Rust

Source details
Declarationnum.imp.dec2flt.decimal_seq.DecimalSeq.try_add_digit
Filenum/imp/../../dec2flt/decimal_seq.rs
Lines74:4–79:5
Program versionRevised program