Program Rust
try_add_digit
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
70 // FIXME(tgross35): it may be better for this to return an option71 // FIXME(tgross35): incrementing the digit counter even if we don't push anything72 // seems incorrect.73 pub(super) fn try_add_digit(&mut self, digit: u8) {74 if self.num_digits < Self::MAX_DIGITS {75 self.digits[self.num_digits] = digit;76 }77 self.num_digits += 1;78 }79 80 /// Trim trailing zeros from the buffer.81 // FIXME(tgross35): this could be `.rev().position()` if perf is okayAeneas 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 }Source details
| Declaration | num.imp.dec2flt.decimal_seq.DecimalSeq.try_add_digit |
|---|---|
| File | num/imp/../../dec2flt/decimal_seq.rs |
| Lines | 73:4–78:5 |
| Program version | Original program |