Source context

Program Rust

integer_decode

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

277     // This is the upstream default after substituting `Self::Int = u32`;278     // concreteness is needed only because Charon cannot resolve the generic279     // associated-integer shifts and bit operators for Aeneas.280     fn integer_decode(self) -> (u64, i16, i8) {281         let bits = self.to_bits();282         let sign = if bits >> 31 == 0 { 1 } else { -1 };283         let mut exponent = ((bits & Self::EXPONENT_MASK) >> 23) as i16;284         let mantissa = if exponent == 0 {285             (bits & Self::MANTISSA_MASK) << 1286         } else {287             (bits & Self::MANTISSA_MASK) | (1_u32 << 23)288         };289         exponent -= 127 + 23;290         (mantissa as u64, exponent, sign)291     }292 }293 294 impl Float for f64 {

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

def F32.Insts.Dec2flt_modelNumImpTraitsFloatExtU32.integer_decode
  (self : F32) : Result (Std.U64 × Std.I16 × Std.I8) := do
  let bits ← core.f32.F32.to_bits self
  let i ← bits >>> 31#i32
  let sign ← if i = 0#u32
               then ok 1#i8
               else ok (-1)#i8
  let i1 ← core.f32.F32.EXPONENT_MASK
  let i2 ← lift (bits &&& i1)
  let i3 ← i2 >>> 23#i32
  let exponent ← lift (UScalar.hcast .I16 i3)
  let mantissa ←
    if exponent = 0#i16
    then
      do
      let i4 ← core.f32.F32.MANTISSA_MASK
      let i5 ← lift (bits &&& i4)
      i5 <<< 1#i32
    else
      do
      let i4 ← core.f32.F32.MANTISSA_MASK
      let i5 ← lift (bits &&& i4)
      let i6 ← 1#u32 <<< 23#i32
      ok (i5 ||| i6)
  let i4 ← 127#i16 + 23#i16
  let exponent1 ← exponent - i4
  let i5 ← lift (UScalar.cast .U64 mantissa)
  ok (i5, exponent1, sign)
Operations used here

EXPONENT_MASK · Rust library

MANTISSA_MASK · Rust library

to_bits · Rust library

Source details
DeclarationF32.Insts.Dec2flt_modelNumImpTraitsFloatExtU32.integer_decode
Filenum/imp/../../traits.rs
Lines280:4–291:5
Program versionPreparation 1