diff options
Diffstat (limited to 'library/std/src/f32.rs')
| -rw-r--r-- | library/std/src/f32.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs index 19fb24c8ee2..980e7f7793a 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"] |
