Repository: rust-lang/rust
File: library/core/src/num/f128.rs (Rust)

Code before:
    /// and its sign. See the [specification of NaN bit patterns](f32#nan-bit-patterns) for more
    /// info.
    ///
    /// This constant is guaranteed to be a quiet NaN (on targets that follow the Rust assumptions
    /// that the quiet/signaling bit being set to 1 indicates a quiet NaN). Beyond that, nothing is
    /// guaranteed about the specific bit pattern chosen here: both payload and sign are arbitrary.
    /// The concrete bit pattern may change across Rust versions and target platforms.
    #[allow(clippy::eq_op)]
    #[rustc_diagnostic_item = "f128_nan"]
    #[unstable(feature = "f128", issue = "116909")]
    pub const NAN: f128 = 0.0_f128 / 0.0_f128;

    /// Infinity (∞).
    #[unstable(feature = "f128", issue = "116909")]
    pub const INFINITY: f128 = 1.0_f128 / 0.0_f128;

    /// Negative infinity (−∞).
    #[unstable(feature = "f128", issue = "116909")]
    pub const NEG_INFINITY: f128 = -1.0_f128 / 0.0_f128;

    /// Maximum integer that can be represented exactly in an [`f128`] value,
    /// with no other integer converting to the same floating point value.
    ///
    /// Values contained inclusively within [`MIN_EXACT_INTEGER`] to
    /// [`MAX_EXACT_INTEGER`] can be losslessly converted between integer
    /// and floating point.
    ///
    /// [`MAX_EXACT_INTEGER`]: f128::MAX_EXACT_INTEGER
    /// [`MIN_EXACT_INTEGER`]: f128::MIN_EXACT_INTEGER
    // #[unstable(feature = "f128", issue = "116909")]
    #[unstable(feature = "float_exact_integer_constants", issue = "152466")]
    pub const MAX_EXACT_INTEGER: i128 = (1 << Self::MANTISSA_DIGITS) - 1;

    /// Minimum integer that can be represented exactly in an [`f128`] value,
    /// with no other integer converting to the same floating point value.
    ///
    /// Values contained inclusively within [`MIN_EXACT_INTEGER`] to
    /// [`MAX_EXACT_INTEGER`] can be losslessly converted between integer
    /// and floating point.
    ///
    /// [`MAX_EXACT_INTEGER`]: f128::MAX_EXACT_INTEGER
    /// [`MIN_EXACT_INTEGER`]: f128::MIN_EXACT_INTEGER
    // #[unstable(feature = "f128", issue = "116909")]
    #[unstable(feature = "float_exact_integer_constants", issue = "152466")]
    pub const MIN_EXACT_INTEGER: i128 = -Self::MAX_EXACT_INTEGER;

    /// Sign bit
    pub(crate) const SIGN_MASK: u128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;

    /// Exponent mask
    pub(crate) const EXP_MASK: u128 = 0x7fff_0000_0000_0000_0000_0000_0000_0000;

Review comment (suggestion):
It would be good to strengthen that the property is 1:1 rather than being the max roundtripping integer, since based on discussion this is definitely a tripping point. Perhaps something like the following:

> Additionally, if a given `x = unknown_int as f128 as i128` satisfies the property `MIN_EXACT_INTEGER <= x <= MAX_EXACT_INTEGER`, then `x` is guaranteed to have the same value as `unknown_int`; that is, an integer within this range has a "one to one" mapping with `f128`. `f128::MAX_EXACT_INTEGER + 1` technically round trips losslessly with `f128` but there are multiple values of `f128` that may map to `f128::MAX_EXACT_INTEGER + 1`, so it does not satisfy this "one to one" property.

Code after:
    /// Note that IEEE 754 doesn't define just a single NaN value; a plethora of bit patterns are
    /// considered to be NaN. Furthermore, the standard makes a difference between a "signaling" and
    /// a "quiet" NaN, and allows inspecting its "payload" (the unspecified bits in the bit pattern)
    /// and its sign. See the [specification of NaN bit patterns](f32#nan-bit-patterns) for more
    /// info.
    ///
    /// This constant is guaranteed to be a quiet NaN (on targets that follow the Rust assumptions
    /// that the quiet/signaling bit being set to 1 indicates a quiet NaN). Beyond that, nothing is
    /// guaranteed about the specific bit pattern chosen here: both payload and sign are arbitrary.
    /// The concrete bit pattern may change across Rust versions and target platforms.
    #[allow(clippy::eq_op)]
    #[rustc_diagnostic_item = "f128_nan"]
    #[unstable(feature = "f128", issue = "116909")]
    pub const NAN: f128 = 0.0_f128 / 0.0_f128;

    /// Infinity (∞).
    #[unstable(feature = "f128", issue = "116909")]
    pub const INFINITY: f128 = 1.0_f128 / 0.0_f128;

    /// Negative infinity (−∞).
    #[unstable(feature = "f128", issue = "116909")]
    pub const NEG_INFINITY: f128 = -1.0_f128 / 0.0_f128;

    /// Maximum integer that can be represented exactly in an [`f128`] value,
    /// with no other integer converting to the same floating point value.
    ///
    /// For an integer `x` which satisfies `MIN_EXACT_INTEGER <= x <= MAX_EXACT_INTEGER`,
    /// there is a "one-to-one" mapping between [`i128`] and [`f128`] values.
    /// `MAX_EXACT_INTEGER + 1` also converts losslessly to [`f128`] and back to
    /// [`i128`], but `MAX_EXACT_INTEGER + 2` converts to the same [`f128`] value
    /// (and back to `MAX_EXACT_INTEGER + 1` as an integer) so there is not a
    /// "one-to-one" mapping.
    ///
    /// [`MAX_EXACT_INTEGER`]: f128::MAX_EXACT_INTEGER
    /// [`MIN_EXACT_INTEGER`]: f128::MIN_EXACT_INTEGER
    /// ```
    /// #![feature(f128)]
    /// #![feature(float_exact_integer_constants)]
    /// # // FIXME(#152635): Float rounding on `i586` does not adhere to IEEE 754
    /// # #[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))] {
    /// # #[cfg(target_has_reliable_f128)] {
    /// let max_exact_int = f128::MAX_EXACT_INTEGER;
    /// assert_eq!(max_exact_int, max_exact_int as f128 as i128);
    /// assert_eq!(max_exact_int + 1, (max_exact_int + 1) as f128 as i128);
    /// assert_ne!(max_exact_int + 2, (max_exact_int + 2) as f128 as i128);
    ///
    /// // Beyond `f128::MAX_EXACT_INTEGER`, multiple integers can map to one float value
    /// assert_eq!((max_exact_int + 1) as f128, (max_exact_int + 2) as f128);
    /// # }}
    /// ```
    // #[unstable(feature = "f128", issue = "116909")]