diff --git a/library/std/src/f128.rs b/library/std/src/f128.rs index 14ce2b69ca427..4c9a4d8a96548 100644 --- a/library/std/src/f128.rs +++ b/library/std/src/f128.rs @@ -468,6 +468,8 @@ impl f128 { /// Returns the natural logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, @@ -489,6 +491,16 @@ impl f128 { /// assert!(abs_difference <= f128::EPSILON); /// # } /// ``` + /// + /// Non-positive values: + /// ``` + /// #![feature(f128)] + /// # #[cfg(reliable_f128_math)] { + /// + /// assert_eq!(0_f128.ln(), f128::NEG_INFINITY); + /// assert!((-42_f128).ln().is_nan()); + /// # } + /// ``` #[inline] #[rustc_allow_incoherent_impl] #[unstable(feature = "f128", issue = "116909")] @@ -499,6 +511,8 @@ impl f128 { /// Returns the logarithm of the number with respect to an arbitrary base. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// The result might not be correctly rounded owing to implementation details; /// `self.log2()` can produce more accurate results for base 2, and /// `self.log10()` can produce more accurate results for base 10. @@ -522,6 +536,16 @@ impl f128 { /// assert!(abs_difference <= f128::EPSILON); /// # } /// ``` + /// + /// Non-positive values: + /// ``` + /// #![feature(f128)] + /// # #[cfg(reliable_f128_math)] { + /// + /// assert_eq!(0_f128.log(10.0), f128::NEG_INFINITY); + /// assert!((-42_f128).log(10.0).is_nan()); + /// # } + /// ``` #[inline] #[rustc_allow_incoherent_impl] #[unstable(feature = "f128", issue = "116909")] @@ -532,6 +556,8 @@ impl f128 { /// Returns the base 2 logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, @@ -551,6 +577,16 @@ impl f128 { /// assert!(abs_difference <= f128::EPSILON); /// # } /// ``` + /// + /// Non-positive values: + /// ``` + /// #![feature(f128)] + /// # #[cfg(reliable_f128_math)] { + /// + /// assert_eq!(0_f128.log2(), f128::NEG_INFINITY); + /// assert!((-42_f128).log2().is_nan()); + /// # } + /// ``` #[inline] #[rustc_allow_incoherent_impl] #[unstable(feature = "f128", issue = "116909")] @@ -561,6 +597,8 @@ impl f128 { /// Returns the base 10 logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, @@ -580,6 +618,16 @@ impl f128 { /// assert!(abs_difference <= f128::EPSILON); /// # } /// ``` + /// + /// Non-positive values: + /// ``` + /// #![feature(f128)] + /// # #[cfg(reliable_f128_math)] { + /// + /// assert_eq!(0_f128.log10(), f128::NEG_INFINITY); + /// assert!((-42_f128).log10().is_nan()); + /// # } + /// ``` #[inline] #[rustc_allow_incoherent_impl] #[unstable(feature = "f128", issue = "116909")] @@ -966,6 +1014,8 @@ impl f128 { /// Returns `ln(1+n)` (natural logarithm) more accurately than if /// the operations were performed separately. /// + /// This returns NaN when `n < -1.0`, and negative infinity when `n == -1.0`. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, @@ -989,6 +1039,16 @@ impl f128 { /// assert!(abs_difference < 1e-10); /// # } /// ``` + /// + /// Out-of-range values: + /// ``` + /// #![feature(f128)] + /// # #[cfg(reliable_f128_math)] { + /// + /// assert_eq!((-1.0_f128).ln_1p(), f128::NEG_INFINITY); + /// assert!((-2.0_f128).ln_1p().is_nan()); + /// # } + /// ``` #[inline] #[doc(alias = "log1p")] #[must_use = "method returns a new number and does not mutate the original value"] diff --git a/library/std/src/f16.rs b/library/std/src/f16.rs index 0af69dff05add..f94e285a4c3fa 100644 --- a/library/std/src/f16.rs +++ b/library/std/src/f16.rs @@ -468,6 +468,8 @@ impl f16 { /// Returns the natural logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, @@ -489,6 +491,16 @@ impl f16 { /// assert!(abs_difference <= f16::EPSILON); /// # } /// ``` + /// + /// Non-positive values: + /// ``` + /// #![feature(f16)] + /// # #[cfg(reliable_f16_math)] { + /// + /// assert_eq!(0_f16.ln(), f16::NEG_INFINITY); + /// assert!((-42_f16).ln().is_nan()); + /// # } + /// ``` #[inline] #[rustc_allow_incoherent_impl] #[unstable(feature = "f16", issue = "116909")] @@ -499,6 +511,8 @@ impl f16 { /// Returns the logarithm of the number with respect to an arbitrary base. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// The result might not be correctly rounded owing to implementation details; /// `self.log2()` can produce more accurate results for base 2, and /// `self.log10()` can produce more accurate results for base 10. @@ -522,6 +536,16 @@ impl f16 { /// assert!(abs_difference <= f16::EPSILON); /// # } /// ``` + /// + /// Non-positive values: + /// ``` + /// #![feature(f16)] + /// # #[cfg(reliable_f16_math)] { + /// + /// assert_eq!(0_f16.log(10.0), f16::NEG_INFINITY); + /// assert!((-42_f16).log(10.0).is_nan()); + /// # } + /// ``` #[inline] #[rustc_allow_incoherent_impl] #[unstable(feature = "f16", issue = "116909")] @@ -532,6 +556,8 @@ impl f16 { /// Returns the base 2 logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, @@ -551,6 +577,16 @@ impl f16 { /// assert!(abs_difference <= f16::EPSILON); /// # } /// ``` + /// + /// Non-positive values: + /// ``` + /// #![feature(f16)] + /// # #[cfg(reliable_f16_math)] { + /// + /// assert_eq!(0_f16.log2(), f16::NEG_INFINITY); + /// assert!((-42_f16).log2().is_nan()); + /// # } + /// ``` #[inline] #[rustc_allow_incoherent_impl] #[unstable(feature = "f16", issue = "116909")] @@ -561,6 +597,8 @@ impl f16 { /// Returns the base 10 logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, @@ -580,6 +618,16 @@ impl f16 { /// assert!(abs_difference <= f16::EPSILON); /// # } /// ``` + /// + /// Non-positive values: + /// ``` + /// #![feature(f16)] + /// # #[cfg(reliable_f16_math)] { + /// + /// assert_eq!(0_f16.log10(), f16::NEG_INFINITY); + /// assert!((-42_f16).log10().is_nan()); + /// # } + /// ``` #[inline] #[rustc_allow_incoherent_impl] #[unstable(feature = "f16", issue = "116909")] @@ -964,6 +1012,8 @@ impl f16 { /// Returns `ln(1+n)` (natural logarithm) more accurately than if /// the operations were performed separately. /// + /// This returns NaN when `n < -1.0`, and negative infinity when `n == -1.0`. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, @@ -987,6 +1037,16 @@ impl f16 { /// assert!(abs_difference < 1e-4); /// # } /// ``` + /// + /// Out-of-range values: + /// ``` + /// #![feature(f16)] + /// # #[cfg(reliable_f16_math)] { + /// + /// assert_eq!((-1.0_f16).ln_1p(), f16::NEG_INFINITY); + /// assert!((-2.0_f16).ln_1p().is_nan()); + /// # } + /// ``` #[inline] #[doc(alias = "log1p")] #[rustc_allow_incoherent_impl] diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs index 295eee8700af2..58584bcce1c5e 100644 --- a/library/std/src/f32.rs +++ b/library/std/src/f32.rs @@ -424,6 +424,8 @@ impl f32 { /// Returns the natural logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and @@ -441,6 +443,12 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + /// + /// Non-positive values: + /// ``` + /// assert_eq!(0_f32.ln(), f32::NEG_INFINITY); + /// assert!((-42_f32).ln().is_nan()); + /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] @@ -451,6 +459,8 @@ impl f32 { /// Returns the logarithm of the number with respect to an arbitrary base. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// The result might not be correctly rounded owing to implementation details; /// `self.log2()` can produce more accurate results for base 2, and /// `self.log10()` can produce more accurate results for base 10. @@ -470,6 +480,12 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + /// + /// Non-positive values: + /// ``` + /// assert_eq!(0_f32.log(10.0), f32::NEG_INFINITY); + /// assert!((-42_f32).log(10.0).is_nan()); + /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] @@ -480,6 +496,8 @@ impl f32 { /// Returns the base 2 logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and @@ -495,6 +513,12 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + /// + /// Non-positive values: + /// ``` + /// assert_eq!(0_f32.log2(), f32::NEG_INFINITY); + /// assert!((-42_f32).log2().is_nan()); + /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] @@ -505,6 +529,8 @@ impl f32 { /// Returns the base 10 logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and @@ -520,6 +546,12 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + /// + /// Non-positive values: + /// ``` + /// assert_eq!(0_f32.log10(), f32::NEG_INFINITY); + /// assert!((-42_f32).log10().is_nan()); + /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] @@ -893,6 +925,8 @@ impl f32 { /// Returns `ln(1+n)` (natural logarithm) more accurately than if /// the operations were performed separately. /// + /// This returns NaN when `n < -1.0`, and negative infinity when `n == -1.0`. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and @@ -911,6 +945,12 @@ impl f32 { /// /// assert!(abs_difference < 1e-10); /// ``` + /// + /// Out-of-range values: + /// ``` + /// assert_eq!((-1.0_f32).ln_1p(), f32::NEG_INFINITY); + /// assert!((-2.0_f32).ln_1p().is_nan()); + /// ``` #[doc(alias = "log1p")] #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] diff --git a/library/std/src/f64.rs b/library/std/src/f64.rs index 0d713ecbc7312..ff708172c1427 100644 --- a/library/std/src/f64.rs +++ b/library/std/src/f64.rs @@ -424,6 +424,8 @@ impl f64 { /// Returns the natural logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and @@ -441,6 +443,12 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + /// + /// Non-positive values: + /// ``` + /// assert_eq!(0_f64.ln(), f64::NEG_INFINITY); + /// assert!((-42_f64).ln().is_nan()); + /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] @@ -451,6 +459,8 @@ impl f64 { /// Returns the logarithm of the number with respect to an arbitrary base. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// The result might not be correctly rounded owing to implementation details; /// `self.log2()` can produce more accurate results for base 2, and /// `self.log10()` can produce more accurate results for base 10. @@ -470,6 +480,12 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + /// + /// Non-positive values: + /// ``` + /// assert_eq!(0_f64.log(10.0), f64::NEG_INFINITY); + /// assert!((-42_f64).log(10.0).is_nan()); + /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] @@ -480,6 +496,8 @@ impl f64 { /// Returns the base 2 logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and @@ -495,6 +513,12 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + /// + /// Non-positive values: + /// ``` + /// assert_eq!(0_f64.log2(), f64::NEG_INFINITY); + /// assert!((-42_f64).log2().is_nan()); + /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] @@ -505,6 +529,8 @@ impl f64 { /// Returns the base 10 logarithm of the number. /// + /// This returns NaN when the number is negative, and negative infinity when number is zero. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and @@ -520,6 +546,12 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + /// + /// Non-positive values: + /// ``` + /// assert_eq!(0_f64.log10(), f64::NEG_INFINITY); + /// assert!((-42_f64).log10().is_nan()); + /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] @@ -893,6 +925,8 @@ impl f64 { /// Returns `ln(1+n)` (natural logarithm) more accurately than if /// the operations were performed separately. /// + /// This returns NaN when `n < -1.0`, and negative infinity when `n == -1.0`. + /// /// # Unspecified precision /// /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and @@ -911,6 +945,12 @@ impl f64 { /// /// assert!(abs_difference < 1e-20); /// ``` + /// + /// Out-of-range values: + /// ``` + /// assert_eq!((-1.0_f64).ln_1p(), f64::NEG_INFINITY); + /// assert!((-2.0_f64).ln_1p().is_nan()); + /// ``` #[doc(alias = "log1p")] #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"]