Program Rust
body
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
48 let mut exp2 = 0_i32;49 let mut loop_result = None;50 // Shift right toward (1/2 ... 1].51 while d.decimal_point > 0 && loop_result.is_none() {52 let n = d.decimal_point as usize;53 let shift = get_shift(n);54 d.right_shift(shift);55 if d.decimal_point < -DecimalSeq::DECIMAL_POINT_RANGE {56 // The source returns `fp_zero` at this exact point. Storing that57 // result and terminating the loop performs no later loop update;58 // the return below is therefore behavior-identical and avoids an59 // Aeneas restriction on returns from nested loop translation.60 loop_result = Some(fp_zero);61 } else {62 exp2 += shift as i32;63 }64 }65 if let Some(result) = loop_result {66 return result;67 }Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
@[rust_loop_body]
def num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
{F : Type} {Clause0_Int : Type} (traitsFloatInst : num.imp.traits.Float F
Clause0_Int) (fp_zero : num.imp.dec2flt.common.BiasedFp) (i : Std.Usize)
(i1 : Std.I32) (b : Bool) (a : Array Std.U8 768#usize) (exp2 : Std.I32)
(loop_result : Option num.imp.dec2flt.common.BiasedFp) :
Result (ControlFlow (Std.Usize × Std.I32 × Bool × (Array Std.U8 768#usize)
× Std.I32 × (Option num.imp.dec2flt.common.BiasedFp)) (Std.Usize ×
Std.I32 × Bool × (Array Std.U8 768#usize) × Std.I32 × (Option
num.imp.dec2flt.common.BiasedFp)))
:= do
if i1 > 0#i32
then
let b1 := core.option.Option.is_none loop_result
if b1
then
let n ← lift (IScalar.hcast .Usize i1)
let shift ←
num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
traitsFloatInst () n
let d ←
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
{ num_digits := i, decimal_point := i1, truncated := b, digits := a }
shift
let i2 ← -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
if d.decimal_point < i2
then
ok (cont (d.num_digits, d.decimal_point, d.truncated, d.digits, exp2,
some fp_zero))
else
let i3 ← lift (UScalar.hcast .I32 shift)
let exp21 ← exp2 + i3
ok (cont (d.num_digits, d.decimal_point, d.truncated, d.digits, exp21,
loop_result))
else ok (done (i, i1, b, a, exp2, loop_result))
else ok (done (i, i1, b, a, exp2, loop_result))Operations used here
Other extracted objects at this span
Source details
| Declaration | num.imp.dec2flt.slow.parse_long_mantissa_loop0.body |
|---|---|
| File | num/imp/../../dec2flt/slow.rs |
| Lines | 51:4–64:5 |
| Program version | Original program |