Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document results of non-positive logarithms #137357

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions library/std/src/f128.rs
Original file line number Diff line number Diff line change
@@ -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"]
60 changes: 60 additions & 0 deletions library/std/src/f16.rs
Original file line number Diff line number Diff line change
@@ -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]
40 changes: 40 additions & 0 deletions library/std/src/f32.rs
Original file line number Diff line number Diff line change
@@ -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"]
Loading
Loading