Auto merge of #63871 - BatmanAoD:FloatFnMustUse, r=withoutboats
Add #[must_use] to all functions 'fn(float) -> float' These are pure functions. ```rust impl f32/f64 { fn floor(self) -> Self; fn ceil(self) -> Self; fn round(self) -> Self; fn trunc(self) -> Self; fn fract(self) -> Self; fn abs(self) -> Self; fn signum(self) -> Self; fn mul_add(self, a: Self, b: Self) -> Self; fn div_euclid(self, rhs: Self) -> Self; fn rem_euclid(self, rhs: Self) -> Self; fn powi(self, n: i32) -> Self; fn powf(self, n: Self) -> Self; fn sqrt(self) -> Self; fn exp(self) -> Self; fn exp2(self) -> Self; fn ln(self) -> Self; fn log(self, base: Self) -> Self; fn log2(self) -> Self; fn log10(self) -> Self; fn abs_sub(self, other: Self) -> Self; fn cbrt(self) -> Self; fn hypot(self, other: Self) -> Self; fn sin(self) -> Self; fn cos(self) -> Self; fn tan(self) -> Self; fn asin(self) -> Self; fn acos(self) -> Self; fn atan(self) -> Self; fn atan2(self, other: Self) -> Self; fn exp_m1(self) -> Self; fn ln_1p(self) -> Self; fn sinh(self) -> Self; fn cosh(self) -> Self; fn tanh(self) -> Self; fn asinh(self) -> Self; fn acosh(self) -> Self; fn atanh(self) -> Self; fn clamp(self, min: Self, max: Self) -> Self; } ``` Part of #48926
This commit is contained in:
commit
ac162c6abe
@ -40,6 +40,7 @@ impl f32 {
|
||||
/// assert_eq!(g.floor(), 3.0);
|
||||
/// assert_eq!(h.floor(), -4.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn floor(self) -> f32 {
|
||||
@ -73,6 +74,7 @@ impl f32 {
|
||||
/// assert_eq!(f.ceil(), 4.0);
|
||||
/// assert_eq!(g.ceil(), 4.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn ceil(self) -> f32 {
|
||||
@ -95,6 +97,7 @@ impl f32 {
|
||||
/// assert_eq!(f.round(), 3.0);
|
||||
/// assert_eq!(g.round(), -3.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn round(self) -> f32 {
|
||||
@ -114,6 +117,7 @@ impl f32 {
|
||||
/// assert_eq!(g.trunc(), 3.0);
|
||||
/// assert_eq!(h.trunc(), -3.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn trunc(self) -> f32 {
|
||||
@ -135,6 +139,7 @@ impl f32 {
|
||||
/// assert!(abs_difference_x <= f32::EPSILON);
|
||||
/// assert!(abs_difference_y <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn fract(self) -> f32 { self - self.trunc() }
|
||||
@ -158,6 +163,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(f32::NAN.abs().is_nan());
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn abs(self) -> f32 {
|
||||
@ -182,6 +188,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(f32::NAN.signum().is_nan());
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn signum(self) -> f32 {
|
||||
@ -213,8 +220,8 @@ impl f32 {
|
||||
///
|
||||
/// assert!(f32::NAN.copysign(1.0).is_nan());
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "copysign", since = "1.35.0")]
|
||||
pub fn copysign(self, sign: f32) -> f32 {
|
||||
unsafe { intrinsics::copysignf32(self, sign) }
|
||||
@ -240,6 +247,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn mul_add(self, a: f32, b: f32) -> f32 {
|
||||
@ -263,6 +271,7 @@ impl f32 {
|
||||
/// assert_eq!(a.div_euclid(-b), -1.0); // 7.0 >= -4.0 * -1.0
|
||||
/// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[inline]
|
||||
#[stable(feature = "euclidean_division", since = "1.38.0")]
|
||||
pub fn div_euclid(self, rhs: f32) -> f32 {
|
||||
@ -296,6 +305,7 @@ impl f32 {
|
||||
/// // limitation due to round-off error
|
||||
/// assert!((-std::f32::EPSILON).rem_euclid(3.0) != 0.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[inline]
|
||||
#[stable(feature = "euclidean_division", since = "1.38.0")]
|
||||
pub fn rem_euclid(self, rhs: f32) -> f32 {
|
||||
@ -322,6 +332,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn powi(self, n: i32) -> f32 {
|
||||
@ -340,6 +351,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn powf(self, n: f32) -> f32 {
|
||||
@ -367,6 +379,7 @@ impl f32 {
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// assert!(negative.sqrt().is_nan());
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn sqrt(self) -> f32 {
|
||||
@ -393,6 +406,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn exp(self) -> f32 {
|
||||
@ -417,6 +431,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn exp2(self) -> f32 {
|
||||
@ -439,6 +454,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn ln(self) -> f32 {
|
||||
@ -467,6 +483,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn log(self, base: f32) -> f32 { self.ln() / base.ln() }
|
||||
@ -485,6 +502,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn log2(self) -> f32 {
|
||||
@ -508,6 +526,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn log10(self) -> f32 {
|
||||
@ -537,6 +556,7 @@ impl f32 {
|
||||
/// assert!(abs_difference_x <= f32::EPSILON);
|
||||
/// assert!(abs_difference_y <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
#[rustc_deprecated(since = "1.10.0",
|
||||
@ -565,6 +585,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn cbrt(self) -> f32 {
|
||||
@ -587,6 +608,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn hypot(self, other: f32) -> f32 {
|
||||
@ -606,6 +628,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn sin(self) -> f32 {
|
||||
@ -629,6 +652,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn cos(self) -> f32 {
|
||||
@ -651,6 +675,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn tan(self) -> f32 {
|
||||
@ -673,6 +698,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn asin(self) -> f32 {
|
||||
@ -695,6 +721,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn acos(self) -> f32 {
|
||||
@ -716,6 +743,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn atan(self) -> f32 {
|
||||
@ -750,6 +778,7 @@ impl f32 {
|
||||
/// assert!(abs_difference_1 <= f32::EPSILON);
|
||||
/// assert!(abs_difference_2 <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn atan2(self, other: f32) -> f32 {
|
||||
@ -794,6 +823,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn exp_m1(self) -> f32 {
|
||||
@ -815,6 +845,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn ln_1p(self) -> f32 {
|
||||
@ -838,6 +869,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn sinh(self) -> f32 {
|
||||
@ -861,6 +893,7 @@ impl f32 {
|
||||
/// // Same result
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn cosh(self) -> f32 {
|
||||
@ -884,6 +917,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn tanh(self) -> f32 {
|
||||
@ -904,6 +938,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn asinh(self) -> f32 {
|
||||
@ -928,6 +963,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= f32::EPSILON);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn acosh(self) -> f32 {
|
||||
@ -952,6 +988,7 @@ impl f32 {
|
||||
///
|
||||
/// assert!(abs_difference <= 1e-5);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn atanh(self) -> f32 {
|
||||
@ -979,6 +1016,7 @@ impl f32 {
|
||||
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
|
||||
/// assert!((std::f32::NAN).clamp(-2.0, 1.0).is_nan());
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "clamp", issue = "44095")]
|
||||
#[inline]
|
||||
pub fn clamp(self, min: f32, max: f32) -> f32 {
|
||||
@ -1594,18 +1632,18 @@ mod tests {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_greater_than_max() {
|
||||
1.0f32.clamp(3.0, 1.0);
|
||||
let _ = 1.0f32.clamp(3.0, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_is_nan() {
|
||||
1.0f32.clamp(NAN, 1.0);
|
||||
let _ = 1.0f32.clamp(NAN, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_max_is_nan() {
|
||||
1.0f32.clamp(3.0, NAN);
|
||||
let _ = 1.0f32.clamp(3.0, NAN);
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ impl f64 {
|
||||
/// assert_eq!(g.floor(), 3.0);
|
||||
/// assert_eq!(h.floor(), -4.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn floor(self) -> f64 {
|
||||
@ -57,6 +58,7 @@ impl f64 {
|
||||
/// assert_eq!(f.ceil(), 4.0);
|
||||
/// assert_eq!(g.ceil(), 4.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn ceil(self) -> f64 {
|
||||
@ -75,6 +77,7 @@ impl f64 {
|
||||
/// assert_eq!(f.round(), 3.0);
|
||||
/// assert_eq!(g.round(), -3.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn round(self) -> f64 {
|
||||
@ -94,6 +97,7 @@ impl f64 {
|
||||
/// assert_eq!(g.trunc(), 3.0);
|
||||
/// assert_eq!(h.trunc(), -3.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn trunc(self) -> f64 {
|
||||
@ -113,6 +117,7 @@ impl f64 {
|
||||
/// assert!(abs_difference_x < 1e-10);
|
||||
/// assert!(abs_difference_y < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn fract(self) -> f64 { self - self.trunc() }
|
||||
@ -136,6 +141,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(f64::NAN.abs().is_nan());
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn abs(self) -> f64 {
|
||||
@ -160,6 +166,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(f64::NAN.signum().is_nan());
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn signum(self) -> f64 {
|
||||
@ -191,9 +198,9 @@ impl f64 {
|
||||
///
|
||||
/// assert!(f64::NAN.copysign(1.0).is_nan());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "copysign", since = "1.35.0")]
|
||||
#[inline]
|
||||
pub fn copysign(self, sign: f64) -> f64 {
|
||||
unsafe { intrinsics::copysignf64(self, sign) }
|
||||
}
|
||||
@ -216,6 +223,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn mul_add(self, a: f64, b: f64) -> f64 {
|
||||
@ -239,6 +247,7 @@ impl f64 {
|
||||
/// assert_eq!(a.div_euclid(-b), -1.0); // 7.0 >= -4.0 * -1.0
|
||||
/// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[inline]
|
||||
#[stable(feature = "euclidean_division", since = "1.38.0")]
|
||||
pub fn div_euclid(self, rhs: f64) -> f64 {
|
||||
@ -272,6 +281,7 @@ impl f64 {
|
||||
/// // limitation due to round-off error
|
||||
/// assert!((-std::f64::EPSILON).rem_euclid(3.0) != 0.0);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[inline]
|
||||
#[stable(feature = "euclidean_division", since = "1.38.0")]
|
||||
pub fn rem_euclid(self, rhs: f64) -> f64 {
|
||||
@ -295,6 +305,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn powi(self, n: i32) -> f64 {
|
||||
@ -311,6 +322,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn powf(self, n: f64) -> f64 {
|
||||
@ -332,6 +344,7 @@ impl f64 {
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// assert!(negative.sqrt().is_nan());
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn sqrt(self) -> f64 {
|
||||
@ -356,6 +369,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn exp(self) -> f64 {
|
||||
@ -374,6 +388,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn exp2(self) -> f64 {
|
||||
@ -394,6 +409,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn ln(self) -> f64 {
|
||||
@ -416,6 +432,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn log(self, base: f64) -> f64 { self.ln() / base.ln() }
|
||||
@ -432,6 +449,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn log2(self) -> f64 {
|
||||
@ -455,6 +473,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn log10(self) -> f64 {
|
||||
@ -478,6 +497,7 @@ impl f64 {
|
||||
/// assert!(abs_difference_x < 1e-10);
|
||||
/// assert!(abs_difference_y < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
#[rustc_deprecated(since = "1.10.0",
|
||||
@ -504,6 +524,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn cbrt(self) -> f64 {
|
||||
@ -524,6 +545,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn hypot(self, other: f64) -> f64 {
|
||||
@ -543,6 +565,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn sin(self) -> f64 {
|
||||
@ -562,6 +585,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn cos(self) -> f64 {
|
||||
@ -580,6 +604,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-14);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn tan(self) -> f64 {
|
||||
@ -602,6 +627,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn asin(self) -> f64 {
|
||||
@ -624,6 +650,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn acos(self) -> f64 {
|
||||
@ -643,6 +670,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn atan(self) -> f64 {
|
||||
@ -677,6 +705,7 @@ impl f64 {
|
||||
/// assert!(abs_difference_1 < 1e-10);
|
||||
/// assert!(abs_difference_2 < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn atan2(self, other: f64) -> f64 {
|
||||
@ -719,6 +748,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn exp_m1(self) -> f64 {
|
||||
@ -740,6 +770,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn ln_1p(self) -> f64 {
|
||||
@ -763,6 +794,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn sinh(self) -> f64 {
|
||||
@ -786,6 +818,7 @@ impl f64 {
|
||||
/// // Same result
|
||||
/// assert!(abs_difference < 1.0e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn cosh(self) -> f64 {
|
||||
@ -809,6 +842,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1.0e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn tanh(self) -> f64 {
|
||||
@ -827,6 +861,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1.0e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn asinh(self) -> f64 {
|
||||
@ -849,6 +884,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1.0e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn acosh(self) -> f64 {
|
||||
@ -873,6 +909,7 @@ impl f64 {
|
||||
///
|
||||
/// assert!(abs_difference < 1.0e-10);
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn atanh(self) -> f64 {
|
||||
@ -900,6 +937,7 @@ impl f64 {
|
||||
/// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0);
|
||||
/// assert!((std::f64::NAN).clamp(-2.0, 1.0).is_nan());
|
||||
/// ```
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "clamp", issue = "44095")]
|
||||
#[inline]
|
||||
pub fn clamp(self, min: f64, max: f64) -> f64 {
|
||||
@ -1535,18 +1573,18 @@ mod tests {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_greater_than_max() {
|
||||
1.0f64.clamp(3.0, 1.0);
|
||||
let _ = 1.0f64.clamp(3.0, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_is_nan() {
|
||||
1.0f64.clamp(NAN, 1.0);
|
||||
let _ = 1.0f64.clamp(NAN, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_max_is_nan() {
|
||||
1.0f64.clamp(3.0, NAN);
|
||||
let _ = 1.0f64.clamp(3.0, NAN);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user