Skip to content

Commit 2e34ff7

Browse files
committed
Fix documentation and formatting.
1 parent 576426a commit 2e34ff7

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/libcore/cmp.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ pub trait Ord: Eq + PartialOrd<Self> {
483483
}
484484

485485
/// Returns max if self is greater than max, and min if self is less than min.
486-
/// Otherwise this will return self. Panics if min > max.
486+
/// Otherwise this will return self.
487487
///
488488
/// # Examples
489489
///
@@ -494,18 +494,16 @@ pub trait Ord: Eq + PartialOrd<Self> {
494494
/// assert!(0.clamp(-2, 1) == 0);
495495
/// assert!(2.clamp(-2, 1) == 1);
496496
/// ```
497+
///
498+
/// # Panics
499+
/// Panics if min > max.
497500
#[unstable(feature = "clamp", issue = "44095")]
498501
fn clamp(self, min: Self, max: Self) -> Self
499502
where Self: Sized {
500503
assert!(min <= max);
501-
if self < min {
502-
min
503-
}
504-
else if self > max {
505-
max
506-
} else {
507-
self
508-
}
504+
if self < min { min }
505+
else if self > max { max }
506+
else { self }
509507
}
510508
}
511509

src/libstd/f32.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ impl f32 {
10811081
}
10821082

10831083
/// Returns max if self is greater than max, and min if self is less than min.
1084-
/// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN.
1084+
/// Otherwise this returns self.
10851085
///
10861086
/// # Examples
10871087
///
@@ -1093,6 +1093,9 @@ impl f32 {
10931093
/// assert!((2.0f32).clamp(-2.0f32, 1.0f32) == 1.0f32);
10941094
/// assert!((NAN).clamp(-2.0f32, 1.0f32).is_nan());
10951095
/// ```
1096+
///
1097+
/// # Panics
1098+
/// Panics if min > max, min is NaN, or max is NaN.
10961099
#[unstable(feature = "clamp", issue = "44095")]
10971100
#[inline]
10981101
pub fn clamp(self, min: f32, max: f32) -> f32 {

src/libstd/f64.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ impl f64 {
971971
}
972972

973973
/// Returns max if self is greater than max, and min if self is less than min.
974-
/// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN.
974+
/// Otherwise this returns self.
975975
///
976976
/// # Examples
977977
///
@@ -983,6 +983,9 @@ impl f64 {
983983
/// assert!((2.0f64).clamp(-2.0f64, 1.0f64) == 1.0f64);
984984
/// assert!((NAN).clamp(-2.0f64, 1.0f64).is_nan());
985985
/// ```
986+
///
987+
/// # Panics
988+
/// Panics if min > max, min is NaN, or max is NaN.
986989
#[unstable(feature = "clamp", issue = "44095")]
987990
#[inline]
988991
pub fn clamp(self, min: f64, max: f64) -> f64 {

0 commit comments

Comments
 (0)