Program Rust
body
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
213 self.digits[write_index] = new_digit;214 write_index += 1;215 }216 while n > 0 {217 let new_digit = (n >> shift) as u8;218 n = 10 * (n & mask);219 if write_index < Self::MAX_DIGITS {220 self.digits[write_index] = new_digit;221 write_index += 1;222 } else if new_digit > 0 {223 self.truncated = true;224 }225 }226 self.num_digits = write_index;227 self.trim();228 }Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body
(shift : Std.Usize) (mask : Std.U64) (b : Bool) (a : Array Std.U8 768#usize)
(write_index : Std.Usize) (n : Std.U64) :
Result (ControlFlow (Bool × (Array Std.U8 768#usize) × Std.Usize ×
Std.U64) (Bool × (Array Std.U8 768#usize) × Std.Usize))
:= do
if n > 0#u64
then
let i ← n >>> shift
let new_digit ← lift (UScalar.cast .U8 i)
let i1 ← lift (n &&& mask)
let n1 ← 10#u64 * i1
if write_index < num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
then
let a1 ← Array.update a write_index new_digit
let write_index1 ← write_index + 1#usize
ok (cont (b, a1, write_index1, n1))
else
if new_digit > 0#u8
then ok (cont (true, a, write_index, n1))
else ok (cont (b, a, write_index, n1))
else ok (done (b, a, write_index))Operations used here
Other extracted objects at this span
Source details
| Declaration | num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body |
|---|---|
| File | num/imp/../../dec2flt/decimal_seq.rs |
| Lines | 216:8–225:9 |
| Program version | Preparation 2 |