@@ -1276,6 +1276,54 @@ impl f128 {
12761276 self
12771277 }
12781278
1279+ /// Restrict a value to a maximum bound.
1280+ ///
1281+ /// Returns `max` if `self` is greater than `max`. Otherwise this returns `self`. If either `self` or `max` is NaN, the other is returned.
1282+ ///
1283+ /// This is identical to [`f128::min`], but is easier to read when using method call syntax.
1284+ ///
1285+ /// # Examples
1286+ ///
1287+ /// ```
1288+ /// #![feature(f128, clamp_min_max)]
1289+ /// assert_eq!((3.0f128).clamp_max(1.0), 1.0);
1290+ /// assert_eq!((0.0f128).clamp_max(1.0), 0.0);
1291+ /// assert_eq!((f128::NAN).clamp_max(1.0), 1.0);
1292+ /// assert_eq!((0.0f128).clamp_max(f128::NAN), 0.0);
1293+ /// ```
1294+ #[ inline]
1295+ #[ unstable( feature = "f128" , issue = "116909" ) ]
1296+ // #[unstable(feature = "clamp_min_max", issue = "147781")]
1297+ #[ rustc_const_unstable( feature = "f128" , issue = "116909" ) ]
1298+ #[ must_use = "method returns a new number and does not mutate the original value" ]
1299+ pub const fn clamp_max ( self , max : f128 ) -> f128 {
1300+ self . min ( max)
1301+ }
1302+
1303+ /// Restrict a value to a minimum bound.
1304+ ///
1305+ /// Returns `min` if `self` is less than `min`. Otherwise this returns `self`. If either `self` or `min` is NaN, the other is returned.
1306+ ///
1307+ /// This is identical to [`f128::max`], but is easier to read when using method call syntax.
1308+ ///
1309+ /// # Examples
1310+ ///
1311+ /// ```
1312+ /// #![feature(f128, clamp_min_max)]
1313+ /// assert_eq!((-3.0f128).clamp_min(-2.0), -2.0);
1314+ /// assert_eq!((0.0f128).clamp_min(-2.0), 0.0);
1315+ /// assert_eq!((f128::NAN).clamp_min(-2.0), -2.0);
1316+ /// assert_eq!((0.0f128).clamp_min(f128::NAN), 0.0);
1317+ /// ```
1318+ #[ inline]
1319+ #[ unstable( feature = "f128" , issue = "116909" ) ]
1320+ // #[unstable(feature = "clamp_min_max", issue = "147781")]
1321+ #[ rustc_const_unstable( feature = "f128" , issue = "116909" ) ]
1322+ #[ must_use = "method returns a new number and does not mutate the original value" ]
1323+ pub const fn clamp_min ( self , min : f128 ) -> f128 {
1324+ self . max ( min)
1325+ }
1326+
12791327 /// Computes the absolute value of `self`.
12801328 ///
12811329 /// This function always returns the precise result.
0 commit comments