Program Rust
trim
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
80 81 /// Trim trailing zeros from the buffer.82 // FIXME(tgross35): this could be `.rev().position()` if perf is okay83 pub fn trim(&mut self) {84 // All of the following calls to `DecimalSeq::trim` can't panic because:85 //86 // 1. `parse_decimal` sets `num_digits` to a max of `DecimalSeq::MAX_DIGITS`.87 // 2. `right_shift` sets `num_digits` to `write_index`, which is bounded by `num_digits`.88 // 3. `left_shift` `num_digits` to a max of `DecimalSeq::MAX_DIGITS`.89 //90 // Trim is only called in `right_shift` and `left_shift`.91 debug_assert!(self.num_digits <= Self::MAX_DIGITS);92 while self.num_digits != 0 && self.digits[self.num_digits - 1] == 0 {93 self.num_digits -= 1;94 }95 }96 97 pub(super) fn round(&self) -> u64 {98 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 }Source details
| Declaration | num.imp.dec2flt.decimal_seq.DecimalSeq.trim |
|---|---|
| File | num/imp/../../dec2flt/decimal_seq.rs |
| Lines | 83:4–95:5 |
| Program version | Revised program |