Program Rust
final_decimal_point
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
266 267 /// Combine counts in i64 and clamp before casting to i32.268 #[inline]269 pub(super) fn final_decimal_point(270 significant_count: usize,271 fractional_count: usize,272 explicit: i64,273 ) -> i32 {274 // This is the repaired upstream body, not an extraction replacement.275 // Source-valid byte slices bound both counts by isize::MAX on this target;276 // their i64 difference is therefore in range. Retain saturating_add and277 // clamp as source operations, including the zero-count early return.278 if significant_count == 0 {279 return 0;280 }281 let base = significant_count as i64 - fractional_count as i64;282 base.saturating_add(explicit)283 .clamp(-(DecimalSeq::DECIMAL_POINT_RANGE as i64), DecimalSeq::DECIMAL_POINT_RANGE as i64)284 as i32285 }286 287 /// Parse a big integer representation of the float as a decimal.288 pub fn parse_decimal_seq(mut s: &[u8]) -> DecimalSeq {Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
def num.imp.dec2flt.decimal_seq.final_decimal_point
(significant_count : Std.Usize) (fractional_count : Std.Usize)
(explicit : Std.I64) :
Result Std.I32
:= do
if significant_count = 0#usize
then ok 0#i32
else
let i ← lift (UScalar.hcast .I64 significant_count)
let i1 ← lift (UScalar.hcast .I64 fractional_count)
let base ← i - i1
let i2 ← lift (core.num.I64.saturating_add base explicit)
let i3 ←
lift (IScalar.cast .I64
num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE)
let i4 ← -. i3
let i5 ←
lift (IScalar.cast .I64
num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE)
let i6 ← core.cmp.impls.OrdI64.clamp i2 i4 i5
ok (IScalar.cast .I32 i6)Operations used here
Source details
| Declaration | num.imp.dec2flt.decimal_seq.final_decimal_point |
|---|---|
| File | num/imp/../../dec2flt/decimal_seq.rs |
| Lines | 269:0–285:1 |
| Program version | Revised program |