Skip to content

Commit

Permalink
Fix documentation and formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaeroxe committed Sep 1, 2017
1 parent 576426a commit 2e34ff7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
16 changes: 7 additions & 9 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ pub trait Ord: Eq + PartialOrd<Self> {
}

/// Returns max if self is greater than max, and min if self is less than min.
/// Otherwise this will return self. Panics if min > max.
/// Otherwise this will return self.
///
/// # Examples
///
Expand All @@ -494,18 +494,16 @@ pub trait Ord: Eq + PartialOrd<Self> {
/// assert!(0.clamp(-2, 1) == 0);
/// assert!(2.clamp(-2, 1) == 1);
/// ```
///
/// # Panics
/// Panics if min > max.
#[unstable(feature = "clamp", issue = "44095")]
fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized {
assert!(min <= max);
if self < min {
min
}
else if self > max {
max
} else {
self
}
if self < min { min }
else if self > max { max }
else { self }
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ impl f32 {
}

/// Returns max if self is greater than max, and min if self is less than min.
/// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN.
/// Otherwise this returns self.
///
/// # Examples
///
Expand All @@ -1093,6 +1093,9 @@ impl f32 {
/// assert!((2.0f32).clamp(-2.0f32, 1.0f32) == 1.0f32);
/// assert!((NAN).clamp(-2.0f32, 1.0f32).is_nan());
/// ```
///
/// # Panics
/// Panics if min > max, min is NaN, or max is NaN.
#[unstable(feature = "clamp", issue = "44095")]
#[inline]
pub fn clamp(self, min: f32, max: f32) -> f32 {
Expand Down
5 changes: 4 additions & 1 deletion src/libstd/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ impl f64 {
}

/// Returns max if self is greater than max, and min if self is less than min.
/// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN.
/// Otherwise this returns self.
///
/// # Examples
///
Expand All @@ -983,6 +983,9 @@ impl f64 {
/// assert!((2.0f64).clamp(-2.0f64, 1.0f64) == 1.0f64);
/// assert!((NAN).clamp(-2.0f64, 1.0f64).is_nan());
/// ```
///
/// # Panics
/// Panics if min > max, min is NaN, or max is NaN.
#[unstable(feature = "clamp", issue = "44095")]
#[inline]
pub fn clamp(self, min: f64, max: f64) -> f64 {
Expand Down

0 comments on commit 2e34ff7

Please sign in to comment.