Source context

Program Rust

trim

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

79 80     /// Trim trailing zeros from the buffer.81     // FIXME(tgross35): this could be `.rev().position()` if perf is okay82     pub fn trim(&mut self) {83         // All of the following calls to `DecimalSeq::trim` can't panic because:84         //85         //  1. `parse_decimal` sets `num_digits` to a max of `DecimalSeq::MAX_DIGITS`.86         //  2. `right_shift` sets `num_digits` to `write_index`, which is bounded by `num_digits`.87         //  3. `left_shift` `num_digits` to a max of `DecimalSeq::MAX_DIGITS`.88         //89         // Trim is only called in `right_shift` and `left_shift`.90         debug_assert!(self.num_digits <= Self::MAX_DIGITS);91         while self.num_digits != 0 && self.digits[self.num_digits - 1] == 0 {92             self.num_digits -= 1;93         }94     }95 96     pub(super) fn round(&self) -> u64 {97         if self.num_digits == 0 || self.decimal_point < 0 {

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

def num.imp.dec2flt.decimal_seq.DecimalSeq.trim
  (self : num.imp.dec2flt.decimal_seq.DecimalSeq) :
  Result num.imp.dec2flt.decimal_seq.DecimalSeq
  := do
  massert (self.num_digits <=
    num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS)
  let i ←
    num.imp.dec2flt.decimal_seq.DecimalSeq.trim_loop self.num_digits
      self.digits
  ok { self with num_digits := i }
Operations used here

DecimalSeq · Program Rust

MAX_DIGITS · Program Rust

trim_loop · Program Rust

Source details
Declarationnum.imp.dec2flt.decimal_seq.DecimalSeq.trim
Filenum/imp/../../dec2flt/decimal_seq.rs
Lines82:4–94:5
Program versionPreparation 2