Source context

Program Rust

body

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

139         // exactly once per accepted byte and the bound keeps every checked140         // exponent operation in the same safe range as the source.141         let mut count = 0;142         while count < s.len() && s[count].wrapping_sub(b'0') < 10 {143             let digit = s[count].wrapping_sub(b'0');144             if exponent < 0x10000 {145                 exponent = 10 * exponent + digit as i64;146             }147             count += 1;148         }149         *s_ref = &s[count..];150         if negative { Some(-exponent) } else { Some(exponent) }151     } 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 exponent1 ←
        if exponent < 65536#i64
        then
          do
          let i3 ← 10#i64 * exponent
          let i4 ← lift (UScalar.hcast .I64 digit)
          i3 + i4
        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
Lines142:8–148:9
Program versionOriginal program