TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.DirectedSemantics.Positive

Positive directed rounding for arbitrary executable float formats #

The shift-based directed rounders used by Model are related to the independent Flocq-style real semantics at the scaled-mantissa boundary, before subnormal and normal values are packed into interchange fields.

roundAt fmt x mode is the real rounding of every IEEERoundingMode on the same grid, Flocq's round with nearestEven, ceilRound, and floorRound for nearest-even and the two infinity directions. Nearest-away rounding is Flocq's nearestChoice with the tie choice nearestAwayChoice, and rounding away from zero is awayRound.

All definitions are uniform in FloatFormat.

Real rounding in every direction #

@[simp]

Nearest-away rounding rounds the scaled mantissa with ties away from zero.

@[simp]

Rounding away from zero rounds the scaled mantissa away from zero.

Every rounding direction returns a value on the grid of fmt.

Every rounding direction fixes a value already on the grid of fmt.

On a nonnegative real a directed mode is upward rounding when it rounds positive results away from zero, and downward rounding otherwise. The two nearest modes are not directed.

Two reals with the same canonical exponent whose scaled mantissas have the same integer bracket and the same location in it round alike in every direction.

Executable scaled-mantissa rounding #

Floor a natural mantissa after expressing it at targetExponent.

Instances For

    Ceil a natural mantissa after expressing it at targetExponent.

    Instances For
      theorem FloatLib.Floats.Formats.BinaryInterchange.Model.roundMantissaAtExponentUp_ne_zero (mantissa : ℕ) (exponent targetExponent : ℤ) (hm : mantissa ≠ 0) :
      roundMantissaAtExponentUp mantissa exponent targetExponent ≠ 0

      Ceiling alignment preserves nonzeroness of a positive mantissa.

      theorem FloatLib.Floats.Formats.BinaryInterchange.Model.roundMantissaAtExponentDown_le_up (mantissa : ℕ) (exponent targetExponent : ℤ) :
      roundMantissaAtExponentDown mantissa exponent targetExponent ≤ roundMantissaAtExponentUp mantissa exponent targetExponent

      Floor alignment never exceeds ceiling alignment at the same exponent.

      theorem FloatLib.Floats.Formats.BinaryInterchange.Model.roundMantissaAtExponentUp_le_down_add_one (mantissa : ℕ) (exponent targetExponent : ℤ) :
      roundMantissaAtExponentUp mantissa exponent targetExponent ≤ roundMantissaAtExponentDown mantissa exponent targetExponent + 1

      Ceiling alignment is at most one unit above floor alignment.

      theorem FloatLib.Floats.Formats.BinaryInterchange.Model.floor_scaledMagnitude (mantissa : ℕ) (exponent targetExponent : ℤ) :
      Flocq.floorRound (↑mantissa * Flocq.bpow Numerics.binaryRadix (exponent - targetExponent)) = Int.ofNat (roundMantissaAtExponentDown mantissa exponent targetExponent)

      Downward shifting computes the integer floor of a scaled positive dyadic.

      theorem FloatLib.Floats.Formats.BinaryInterchange.Model.ceil_scaledMagnitude (mantissa : ℕ) (exponent targetExponent : ℤ) :
      Flocq.ceilRound (↑mantissa * Flocq.bpow Numerics.binaryRadix (exponent - targetExponent)) = Int.ofNat (roundMantissaAtExponentUp mantissa exponent targetExponent)

      Upward shifting computes the integer ceiling of a scaled positive dyadic.

      theorem FloatLib.Floats.Formats.BinaryInterchange.Model.roundMantissaAtExponentDown_mul_bpow_le (mantissa : ℕ) (exponent targetExponent : ℤ) :
      ↑(roundMantissaAtExponentDown mantissa exponent targetExponent) * bpow targetExponent ≤ ↑mantissa * bpow exponent

      Floor alignment at any target exponent is a lower bound for the exact dyadic magnitude.

      theorem FloatLib.Floats.Formats.BinaryInterchange.Model.le_roundMantissaAtExponentUp_mul_bpow (mantissa : ℕ) (exponent targetExponent : ℤ) :
      ↑mantissa * bpow exponent ≤ ↑(roundMantissaAtExponentUp mantissa exponent targetExponent) * bpow targetExponent

      Ceiling alignment at any target exponent is an upper bound for the exact dyadic magnitude.