Source context

Program Rust

Float

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

64 // observation.  Dropping only `Debug` leaves the concrete floats and all65 // computational bounds unchanged, hence preserves the f64 specialization and66 // every inventoried observation independently of GOAL truth.67 pub trait Float:68     Sized69     + ops::Div<Output = Self>70     + ops::Neg<Output = Self>71     + ops::Mul<Output = Self>72     + ops::Add<Output = Self>73     + PartialEq74     + PartialOrd75     + Default76     + Clone77     + Copy78 {79     /// The unsigned integer with the same size as the float80     type Int: Int + Into<u64>;81 82     /* general constants */83 84     const INFINITY: Self;85     const NEG_INFINITY: Self;86     const NAN: Self;87     const NEG_NAN: Self;88 89     /// Bit width of the float90     const BITS: u32;91 92     /// The number of bits in the significand, *including* the hidden bit.93     const SIG_TOTAL_BITS: u32;94 95     const EXP_MASK: Self::Int;96     const SIG_MASK: Self::Int;97 98     /// The number of bits in the significand, *excluding* the hidden bit.99     const SIG_BITS: u32 = Self::SIG_TOTAL_BITS - 1;100 101     /// Number of bits in the exponent.102     const EXP_BITS: u32 = Self::BITS - Self::SIG_BITS - 1;103 104     /// The saturated (maximum bitpattern) value of the exponent, i.e. the infinite105     /// representation.106     ///107     /// This shifted fully right, use `EXP_MASK` for the shifted value.108     const EXP_SAT: u32 = (1 << Self::EXP_BITS) - 1;109 110     /// Signed version of `EXP_SAT` since we convert a lot.111     const INFINITE_POWER: i32 = Self::EXP_SAT as i32;112 113     /// The exponent bias value. This is also the maximum value of the exponent.114     const EXP_BIAS: u32 = Self::EXP_SAT >> 1;115 116     /// Minimum exponent value of normal values.117     const EXP_MIN: i32 = -(Self::EXP_BIAS as i32 - 1);118 119     /// Round-to-even only happens for negative values of q120     /// when q ≥ −4 in the 64-bit case and when q ≥ −17 in121     /// the 32-bit case.122     ///123     /// When q ≥ 0,we have that 5^q ≤ 2m+1. In the 64-bit case,we124     /// have 5^q ≤ 2m+1 ≤ 2^54 or q ≤ 23. In the 32-bit case,we have125     /// 5^q ≤ 2m+1 ≤ 2^25 or q ≤ 10.126     ///127     /// When q < 0, we have w ≥ (2m+1)×5^−q. We must have that w < 2^64128     /// so (2m+1)×5^−q < 2^64. We have that 2m+1 > 2^53 (64-bit case)129     /// or 2m+1 > 2^24 (32-bit case). Hence,we must have 2^53×5^−q < 2^64130     /// (64-bit) and 2^24×5^−q < 2^64 (32-bit). Hence we have 5^−q < 2^11131     /// or q ≥ −4 (64-bit case) and 5^−q < 2^40 or q ≥ −17 (32-bit case).132     ///133     /// Thus we have that we only need to round ties to even when134     /// we have that q ∈ [−4,23](in the 64-bit case) or q∈[−17,10]135     /// (in the 32-bit case). In both cases,the power of five(5^|q|)136     /// fits in a 64-bit word.137     const MIN_EXPONENT_ROUND_TO_EVEN: i32;138     const MAX_EXPONENT_ROUND_TO_EVEN: i32;139 140     /// Largest decimal exponent for a non-infinite value.141     ///142     /// This is the max exponent in binary converted to the max exponent in decimal. Allows fast143     /// pathing anything larger than `10^LARGEST_POWER_OF_TEN`, which will round to infinity.144     const LARGEST_POWER_OF_TEN: i32;145 146     /// Smallest decimal exponent for a non-zero value. This allows for fast pathing anything147     /// smaller than `10^SMALLEST_POWER_OF_TEN`, which will round to zero.148     ///149     /// The smallest power of ten is represented by `⌊log10(2^-n / (2^64 - 1))⌋`, where `n` is150     /// the smallest power of two. The `2^64 - 1)` denominator comes from the number of values151     /// that are representable by the intermediate storage format. I don't actually know _why_152     /// the storage format is relevant here.153     ///154     /// The values may be calculated using the formula. Unfortunately we cannot calculate them at155     /// compile time since intermediates exceed the range of an `f64`.156     const SMALLEST_POWER_OF_TEN: i32;157 158     /// Returns the category that this number falls into.159     fn classify(self) -> FpCategory;160 161     /// Transmute to the integer representation162     fn to_bits(self) -> Self::Int;163 }164 165 /// Items that ideally would be on `Float`, but don't apply to all float types because they166 /// rely on the mantissa fitting into a `u64` (which isn't true for `f128`).

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

structure num.imp.traits.Float (Self : Type) (Self_Int : Type) where
  INFINITY : Result Self
  NEG_INFINITY : Result Self
  NAN : Result Self
  NEG_NAN : Result Self
  BITS : Result Std.U32
  SIG_TOTAL_BITS : Result Std.U32
  EXP_MASK : Result Self_Int
  SIG_MASK : Result Self_Int
  SIG_BITS : Result Std.U32
  EXP_BITS : Result Std.U32
  EXP_SAT : Result Std.U32
  INFINITE_POWER : Result Std.I32
  EXP_BIAS : Result Std.U32
  EXP_MIN : Result Std.I32
  MIN_EXPONENT_ROUND_TO_EVEN : Result Std.I32
  MAX_EXPONENT_ROUND_TO_EVEN : Result Std.I32
  LARGEST_POWER_OF_TEN : Result Std.I32
  SMALLEST_POWER_OF_TEN : Result Std.I32
  coreopsarithDivInst : core.ops.arith.Div Self Self Self
  coreopsarithNegInst : core.ops.arith.Neg Self Self
  coreopsarithMulInst : core.ops.arith.Mul Self Self Self
  coreopsarithAddInst : core.ops.arith.Add Self Self Self
  corecmpPartialEqInst : core.cmp.PartialEq Self Self
  corecmpPartialOrdInst : core.cmp.PartialOrd Self Self
  coredefaultDefaultInst : core.default.Default Self
  corecloneCloneInst : core.clone.Clone Self
  coremarkerCopyInst : core.marker.Copy Self
  IntInst : num.imp.traits.Int Self_Int
  coreconvertIntoSelf_IntU64Inst : core.convert.Into Self_Int Std.U64
  classify : Self → Result core.num.FpCategory
  to_bits : Self → Result Self_Int
Operations used here

FpCategory · Rust library

Add · Rust library

Mul · Rust library

Div · Rust library

Neg · Rust library

Int · Program Rust

Source details
Declarationnum.imp.traits.Float
Filenum/imp/../../traits.rs
Lines67:0–163:1
Program versionPreparation 1