Source context

Program Rust

parse_many_digits

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

101 // This is the source many-digit retry as a transparent helper.  Isolating its102 // rebased slices avoids an Aeneas context-join failure; both calls, the branch,103 // the offset arithmetic, and the explicit-exponent addition are unchanged.104 fn parse_many_digits(start: &[u8], int_end: &[u8], exp_number: i64) -> (u64, i64) {105     let mut mantissa = 0;106     let mut s = start;107     try_parse_19digits(&mut s, &mut mantissa);108     let mut exponent = if mantissa >= MIN_19DIGIT_INT {109         int_end.offset_from(s)110     } else {111         s = &s[1..];112         let before = s;113         try_parse_19digits(&mut s, &mut mantissa);114         -s.offset_from(before)115     } as i64;116     exponent += exp_number;117     (mantissa, exponent)118 }119 120 /// Parse the scientific notation component of a float.121 pub(super) fn parse_scientific(s_ref: &mut &[u8]) -> Option<i64> {

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

def num.imp.dec2flt.parse.parse_many_digits
  (start : Slice Std.U8) (int_end : Slice Std.U8) (exp_number : Std.I64) :
  Result (Std.U64 × Std.I64)
  := do
  let (start1, mantissa) ←
    num.imp.dec2flt.parse.try_parse_19digits start 0#u64
  let (mantissa1, i) ←
    if mantissa >= num.imp.dec2flt.parse.MIN_19DIGIT_INT
    then
      do
      let i1 ←
        SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from
          int_end start1
      ok (mantissa, i1)
    else
      do
      let s ←
        core.slice.index.Slice.index
          (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) start1
          { start := 1#usize }
      let (s1, mantissa2) ←
        num.imp.dec2flt.parse.try_parse_19digits s mantissa
      let i1 ←
        SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from s1
          s
      let i2 ← -. i1
      ok (mantissa2, i2)
  let exponent ← lift (IScalar.cast .I64 i)
  let exponent1 ← exponent + exp_number
  ok (mantissa1, exponent1)
Operations used here

offset_from · Program Rust

MIN_19DIGIT_INT · Program Rust

try_parse_19digits · Program Rust

Source details
Declarationnum.imp.dec2flt.parse.parse_many_digits
Filenum/imp/../../dec2flt/parse.rs
Lines104:0–118:1
Program versionRevised program