Source context

Program Rust

body

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

142         // and the first nondigit remains in the returned suffix, so the caller143         // performs the same whole-input validation even after updates stop.144         let mut count = 0;145         while count < s.len() && s[count].wrapping_sub(b'0') < 10 {146             let digit = s[count].wrapping_sub(b'0');147             if exponent < (1_i64 << 59) {148                 exponent = 10 * exponent + digit as i64;149             }150             count += 1;151         }152         *s_ref = &s[count..];153         if negative { Some(-exponent) } else { Some(exponent) }154     } else {

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

@[rust_loop_body]
def num.imp.dec2flt.parse.parse_scientific_loop.body
  (s : Slice Std.U8) (exponent : Std.I64) (count : Std.Usize) :
  Result (ControlFlow (Std.I64 × Std.Usize) (Std.I64 × Std.Usize))
  := do
  let i := Slice.len s
  if count < i
  then
    let i1 ← Slice.index_usize s count
    let i2 ← lift (core.num.U8.wrapping_sub i1 48#u8)
    if i2 < 10#u8
    then
      let digit ← lift (core.num.U8.wrapping_sub i1 48#u8)
      let i3 ← 1#i64 <<< 59#i32
      let exponent1 ←
        if exponent < i3
        then
          do
          let i4 ← 10#i64 * exponent
          let i5 ← lift (UScalar.hcast .I64 digit)
          i4 + i5
        else ok exponent
      let count1 ← count + 1#usize
      ok (cont (exponent1, count1))
    else ok (done (exponent, count))
  else ok (done (exponent, count))
Other extracted objects at this span

num.imp.dec2flt.parse.parse_scientific_loop

Source details
Declarationnum.imp.dec2flt.parse.parse_scientific_loop.body
Filenum/imp/../../dec2flt/parse.rs
Lines145:8–151:9
Program versionRevised program