Program Rust
integer_decode
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
224 // Specializing the upstream default removes only unsupported associated-225 // integer operator resolution; these are the same bit operations with226 // `Self::Int = u16` and the same exponent-bias subtraction.227 fn integer_decode(self) -> (u64, i16, i8) {228 let bits = self.to_bits();229 let sign = if bits >> 15 == 0 { 1 } else { -1 };230 let mut exponent = ((bits & Self::EXPONENT_MASK) >> 10) as i16;231 let mantissa = if exponent == 0 {232 (bits & Self::MANTISSA_MASK) << 1233 } else {234 (bits & Self::MANTISSA_MASK) | (1_u16 << 10)235 };236 exponent -= 15 + 10;237 (mantissa as u64, exponent, sign)238 }239 }240 241 impl Float for f32 {Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
def F16.Insts.Dec2flt_modelNumImpTraitsFloatExtU16.integer_decode
(self : F16) : Result (Std.U64 × Std.I16 × Std.I8) := do
let bits ← core.f16.F16.to_bits self
let i ← bits >>> 15#i32
let sign ← if i = 0#u16
then ok 1#i8
else ok (-1)#i8
let i1 ← core.f16.F16.EXPONENT_MASK
let i2 ← lift (bits &&& i1)
let i3 ← i2 >>> 10#i32
let exponent ← lift (UScalar.hcast .I16 i3)
let mantissa ←
if exponent = 0#i16
then
do
let i4 ← core.f16.F16.MANTISSA_MASK
let i5 ← lift (bits &&& i4)
i5 <<< 1#i32
else
do
let i4 ← core.f16.F16.MANTISSA_MASK
let i5 ← lift (bits &&& i4)
let i6 ← 1#u16 <<< 10#i32
ok (i5 ||| i6)
let i4 ← 15#i16 + 10#i16
let exponent1 ← exponent - i4
let i5 ← lift (UScalar.cast .U64 mantissa)
ok (i5, exponent1, sign)Source details
| Declaration | F16.Insts.Dec2flt_modelNumImpTraitsFloatExtU16.integer_decode |
|---|---|
| File | num/imp/../../traits.rs |
| Lines | 227:4–238:5 |
| Program version | Preparation 1 |