Source context

Program Rust

Float

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

71 // Removing those unused requirements admits the same f64 implementation and72 // changes no f64 body, native decision, checked arithmetic, debug assertion,73 // return value, or trace observation, independently of any GOAL's truth.74 pub trait Float:75     Sized76     + ops::Div<Output = Self>77     + ops::Neg<Output = Self>78     + ops::Mul<Output = Self>79     + Copy80 {81     /// The unsigned integer with the same size as the float82     type Int: Int + Into<u64>;83 84     /* general constants */85 86     const INFINITY: Self;87     const NEG_INFINITY: Self;88     const NAN: Self;89     const NEG_NAN: Self;90 91     /// Bit width of the float92     const BITS: u32;93 94     /// The number of bits in the significand, *including* the hidden bit.95     const SIG_TOTAL_BITS: u32;96 97     const EXP_MASK: Self::Int;98     const SIG_MASK: Self::Int;99 100     /// The number of bits in the significand, *excluding* the hidden bit.101     const SIG_BITS: u32 = Self::SIG_TOTAL_BITS - 1;102 103     /// Number of bits in the exponent.104     const EXP_BITS: u32 = Self::BITS - Self::SIG_BITS - 1;105 106     /// The saturated (maximum bitpattern) value of the exponent, i.e. the infinite107     /// representation.108     ///109     /// This shifted fully right, use `EXP_MASK` for the shifted value.110     const EXP_SAT: u32 = (1 << Self::EXP_BITS) - 1;111 112     /// Signed version of `EXP_SAT` since we convert a lot.113     const INFINITE_POWER: i32 = Self::EXP_SAT as i32;114 115     /// The exponent bias value. This is also the maximum value of the exponent.116     const EXP_BIAS: u32 = Self::EXP_SAT >> 1;117 118     /// Minimum exponent value of normal values.119     const EXP_MIN: i32 = -(Self::EXP_BIAS as i32 - 1);120 121     /// Round-to-even only happens for negative values of q122     /// when q ≥ −4 in the 64-bit case and when q ≥ −17 in123     /// the 32-bit case.124     ///125     /// When q ≥ 0,we have that 5^q ≤ 2m+1. In the 64-bit case,we126     /// have 5^q ≤ 2m+1 ≤ 2^54 or q ≤ 23. In the 32-bit case,we have127     /// 5^q ≤ 2m+1 ≤ 2^25 or q ≤ 10.128     ///129     /// When q < 0, we have w ≥ (2m+1)×5^−q. We must have that w < 2^64130     /// so (2m+1)×5^−q < 2^64. We have that 2m+1 > 2^53 (64-bit case)131     /// or 2m+1 > 2^24 (32-bit case). Hence,we must have 2^53×5^−q < 2^64132     /// (64-bit) and 2^24×5^−q < 2^64 (32-bit). Hence we have 5^−q < 2^11133     /// or q ≥ −4 (64-bit case) and 5^−q < 2^40 or q ≥ −17 (32-bit case).134     ///135     /// Thus we have that we only need to round ties to even when136     /// we have that q ∈ [−4,23](in the 64-bit case) or q∈[−17,10]137     /// (in the 32-bit case). In both cases,the power of five(5^|q|)138     /// fits in a 64-bit word.139     const MIN_EXPONENT_ROUND_TO_EVEN: i32;140     const MAX_EXPONENT_ROUND_TO_EVEN: i32;141 142     /// Largest decimal exponent for a non-infinite value.143     ///144     /// This is the max exponent in binary converted to the max exponent in decimal. Allows fast145     /// pathing anything larger than `10^LARGEST_POWER_OF_TEN`, which will round to infinity.146     const LARGEST_POWER_OF_TEN: i32;147 148     /// Smallest decimal exponent for a non-zero value. This allows for fast pathing anything149     /// smaller than `10^SMALLEST_POWER_OF_TEN`, which will round to zero.150     ///151     /// The smallest power of ten is represented by `⌊log10(2^-n / (2^64 - 1))⌋`, where `n` is152     /// the smallest power of two. The `2^64 - 1)` denominator comes from the number of values153     /// that are representable by the intermediate storage format. I don't actually know _why_154     /// the storage format is relevant here.155     ///156     /// The values may be calculated using the formula. Unfortunately we cannot calculate them at157     /// compile time since intermediates exceed the range of an `f64`.158     const SMALLEST_POWER_OF_TEN: i32;159 160     /// Returns the category that this number falls into.161     fn classify(self) -> FpCategory;162 163     /// Transmute to the integer representation164     fn to_bits(self) -> Self::Int;165 }166 167 /// Items that ideally would be on `Float`, but don't apply to all float types because they168 /// 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
  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

Mul · Rust library

Div · Rust library

Neg · Rust library

Int · Program Rust

Source details
Declarationnum.imp.traits.Float
Filenum/imp/../../traits.rs
Lines74:0–165:1
Program versionOriginal program