@@ -275,6 +275,68 @@ impl f128 {
275275 #[ unstable( feature = "f128" , issue = "116909" ) ]
276276 pub const NEG_INFINITY : f128 = -1.0_f128 / 0.0_f128 ;
277277
278+ /// Maximum integer that can be represented exactly in an [`f128`] value,
279+ /// with no other integer converting to the same floating point value.
280+ ///
281+ /// For an integer `x` which satisfies `MIN_EXACT_INTEGER <= x <= MAX_EXACT_INTEGER`,
282+ /// there is a "one-to-one" mapping between [`i128`] and [`f128`] values.
283+ /// `MAX_EXACT_INTEGER + 1` also converts losslessly to [`f128`] and back to
284+ /// [`i128`], but `MAX_EXACT_INTEGER + 2` converts to the same [`f128`] value
285+ /// (and back to `MAX_EXACT_INTEGER + 1` as an integer) so there is not a
286+ /// "one-to-one" mapping.
287+ ///
288+ /// [`MAX_EXACT_INTEGER`]: f128::MAX_EXACT_INTEGER
289+ /// [`MIN_EXACT_INTEGER`]: f128::MIN_EXACT_INTEGER
290+ /// ```
291+ /// #![feature(f128)]
292+ /// #![feature(float_exact_integer_constants)]
293+ /// # #[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))] {
294+ /// # #[cfg(target_has_reliable_f128)] {
295+ /// let max_exact_int = f128::MAX_EXACT_INTEGER;
296+ /// assert_eq!(max_exact_int, max_exact_int as f128 as i128);
297+ /// assert_eq!(max_exact_int + 1, (max_exact_int + 1) as f128 as i128);
298+ /// assert_ne!(max_exact_int + 2, (max_exact_int + 2) as f128 as i128);
299+ ///
300+ /// // Beyond `f128::MAX_EXACT_INTEGER`, multiple integers can map to one float value
301+ /// assert_eq!((max_exact_int + 1) as f128, (max_exact_int + 2) as f128);
302+ /// # }}
303+ /// ```
304+ // #[unstable(feature = "f128", issue = "116909")]
305+ #[ unstable( feature = "float_exact_integer_constants" , issue = "152466" ) ]
306+ pub const MAX_EXACT_INTEGER : i128 = ( 1 << Self :: MANTISSA_DIGITS ) - 1 ;
307+
308+ /// Minimum integer that can be represented exactly in an [`f128`] value,
309+ /// with no other integer converting to the same floating point value.
310+ ///
311+ /// For an integer `x` which satisfies `MIN_EXACT_INTEGER <= x <= MAX_EXACT_INTEGER`,
312+ /// there is a "one-to-one" mapping between [`i128`] and [`f128`] values.
313+ /// `MAX_EXACT_INTEGER + 1` also converts losslessly to [`f128`] and back to
314+ /// [`i128`], but `MAX_EXACT_INTEGER + 2` converts to the same [`f128`] value
315+ /// (and back to `MAX_EXACT_INTEGER + 1` as an integer) so there is not a
316+ /// "one-to-one" mapping.
317+ ///
318+ /// This constant is equivalent to `-MAX_EXACT_INTEGER`.
319+ ///
320+ /// [`MAX_EXACT_INTEGER`]: f128::MAX_EXACT_INTEGER
321+ /// [`MIN_EXACT_INTEGER`]: f128::MIN_EXACT_INTEGER
322+ /// ```
323+ /// #![feature(f128)]
324+ /// #![feature(float_exact_integer_constants)]
325+ /// # #[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))] {
326+ /// # #[cfg(target_has_reliable_f128)] {
327+ /// let min_exact_int = f128::MIN_EXACT_INTEGER;
328+ /// assert_eq!(min_exact_int, min_exact_int as f128 as i128);
329+ /// assert_eq!(min_exact_int - 1, (min_exact_int - 1) as f128 as i128);
330+ /// assert_ne!(min_exact_int - 2, (min_exact_int - 2) as f128 as i128);
331+ ///
332+ /// // Below `f128::MIN_EXACT_INTEGER`, multiple integers can map to one float value
333+ /// assert_eq!((min_exact_int - 1) as f128, (min_exact_int - 2) as f128);
334+ /// # }}
335+ /// ```
336+ // #[unstable(feature = "f128", issue = "116909")]
337+ #[ unstable( feature = "float_exact_integer_constants" , issue = "152466" ) ]
338+ pub const MIN_EXACT_INTEGER : i128 = -Self :: MAX_EXACT_INTEGER ;
339+
278340 /// Sign bit
279341 pub ( crate ) const SIGN_MASK : u128 = 0x8000_0000_0000_0000_0000_0000_0000_0000 ;
280342
0 commit comments