mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
Stabilize clamp
This commit is contained in:
parent
d6b5ffb5b4
commit
a7d3368448
@ -631,14 +631,12 @@ pub trait Ord: Eq + PartialOrd<Self> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(clamp)]
|
|
||||||
///
|
|
||||||
/// assert!((-3).clamp(-2, 1) == -2);
|
/// assert!((-3).clamp(-2, 1) == -2);
|
||||||
/// assert!(0.clamp(-2, 1) == 0);
|
/// assert!(0.clamp(-2, 1) == 0);
|
||||||
/// assert!(2.clamp(-2, 1) == 1);
|
/// assert!(2.clamp(-2, 1) == 1);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "clamp", issue = "44095")]
|
#[stable(feature = "clamp", since = "1.49.0")]
|
||||||
fn clamp(self, min: Self, max: Self) -> Self
|
fn clamp(self, min: Self, max: Self) -> Self
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
@ -891,14 +891,13 @@ impl f32 {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(clamp)]
|
|
||||||
/// assert!((-3.0f32).clamp(-2.0, 1.0) == -2.0);
|
/// assert!((-3.0f32).clamp(-2.0, 1.0) == -2.0);
|
||||||
/// assert!((0.0f32).clamp(-2.0, 1.0) == 0.0);
|
/// assert!((0.0f32).clamp(-2.0, 1.0) == 0.0);
|
||||||
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
|
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
|
||||||
/// assert!((f32::NAN).clamp(-2.0, 1.0).is_nan());
|
/// assert!((f32::NAN).clamp(-2.0, 1.0).is_nan());
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||||
#[unstable(feature = "clamp", issue = "44095")]
|
#[stable(feature = "clamp", since = "1.49.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn clamp(self, min: f32, max: f32) -> f32 {
|
pub fn clamp(self, min: f32, max: f32) -> f32 {
|
||||||
assert!(min <= max);
|
assert!(min <= max);
|
||||||
|
@ -893,14 +893,13 @@ impl f64 {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(clamp)]
|
|
||||||
/// assert!((-3.0f64).clamp(-2.0, 1.0) == -2.0);
|
/// assert!((-3.0f64).clamp(-2.0, 1.0) == -2.0);
|
||||||
/// assert!((0.0f64).clamp(-2.0, 1.0) == 0.0);
|
/// assert!((0.0f64).clamp(-2.0, 1.0) == 0.0);
|
||||||
/// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0);
|
/// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0);
|
||||||
/// assert!((f64::NAN).clamp(-2.0, 1.0).is_nan());
|
/// assert!((f64::NAN).clamp(-2.0, 1.0).is_nan());
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||||
#[unstable(feature = "clamp", issue = "44095")]
|
#[stable(feature = "clamp", since = "1.49.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn clamp(self, min: f64, max: f64) -> f64 {
|
pub fn clamp(self, min: f64, max: f64) -> f64 {
|
||||||
assert!(min <= max);
|
assert!(min <= max);
|
||||||
|
@ -234,7 +234,6 @@
|
|||||||
#![feature(cfg_target_thread_local)]
|
#![feature(cfg_target_thread_local)]
|
||||||
#![feature(char_error_internals)]
|
#![feature(char_error_internals)]
|
||||||
#![feature(char_internals)]
|
#![feature(char_internals)]
|
||||||
#![feature(clamp)]
|
|
||||||
#![feature(concat_idents)]
|
#![feature(concat_idents)]
|
||||||
#![feature(const_cstr_unchecked)]
|
#![feature(const_cstr_unchecked)]
|
||||||
#![feature(const_fn_floating_point_arithmetic)]
|
#![feature(const_fn_floating_point_arithmetic)]
|
||||||
|
Loading…
Reference in New Issue
Block a user