@@ -424,6 +424,8 @@ impl f32 {
424424
425425 /// Returns the natural logarithm of the number.
426426 ///
427+ /// This returns NaN when the number is negative, and negative infinity when number is zero.
428+ ///
427429 /// # Unspecified precision
428430 ///
429431 /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
@@ -441,6 +443,12 @@ impl f32 {
441443 ///
442444 /// assert!(abs_difference <= f32::EPSILON);
443445 /// ```
446+ ///
447+ /// Non-positive values:
448+ /// ```
449+ /// assert_eq!(0_f32.ln(), f32::NEG_INFINITY);
450+ /// assert!((-42_f32).ln().is_nan());
451+ /// ```
444452 #[ rustc_allow_incoherent_impl]
445453 #[ must_use = "method returns a new number and does not mutate the original value" ]
446454 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -451,6 +459,8 @@ impl f32 {
451459
452460 /// Returns the logarithm of the number with respect to an arbitrary base.
453461 ///
462+ /// This returns NaN when the number is negative, and negative infinity when number is zero.
463+ ///
454464 /// The result might not be correctly rounded owing to implementation details;
455465 /// `self.log2()` can produce more accurate results for base 2, and
456466 /// `self.log10()` can produce more accurate results for base 10.
@@ -470,6 +480,12 @@ impl f32 {
470480 ///
471481 /// assert!(abs_difference <= f32::EPSILON);
472482 /// ```
483+ ///
484+ /// Non-positive values:
485+ /// ```
486+ /// assert_eq!(0_f32.log(10.0), f32::NEG_INFINITY);
487+ /// assert!((-42_f32).log(10.0).is_nan());
488+ /// ```
473489 #[ rustc_allow_incoherent_impl]
474490 #[ must_use = "method returns a new number and does not mutate the original value" ]
475491 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -480,6 +496,8 @@ impl f32 {
480496
481497 /// Returns the base 2 logarithm of the number.
482498 ///
499+ /// This returns NaN when the number is negative, and negative infinity when number is zero.
500+ ///
483501 /// # Unspecified precision
484502 ///
485503 /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
@@ -495,6 +513,12 @@ impl f32 {
495513 ///
496514 /// assert!(abs_difference <= f32::EPSILON);
497515 /// ```
516+ ///
517+ /// Non-positive values:
518+ /// ```
519+ /// assert_eq!(0_f32.log2(), f32::NEG_INFINITY);
520+ /// assert!((-42_f32).log2().is_nan());
521+ /// ```
498522 #[ rustc_allow_incoherent_impl]
499523 #[ must_use = "method returns a new number and does not mutate the original value" ]
500524 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -505,6 +529,8 @@ impl f32 {
505529
506530 /// Returns the base 10 logarithm of the number.
507531 ///
532+ /// This returns NaN when the number is negative, and negative infinity when number is zero.
533+ ///
508534 /// # Unspecified precision
509535 ///
510536 /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
@@ -520,6 +546,12 @@ impl f32 {
520546 ///
521547 /// assert!(abs_difference <= f32::EPSILON);
522548 /// ```
549+ ///
550+ /// Non-positive values:
551+ /// ```
552+ /// assert_eq!(0_f32.log10(), f32::NEG_INFINITY);
553+ /// assert!((-42_f32).log10().is_nan());
554+ /// ```
523555 #[ rustc_allow_incoherent_impl]
524556 #[ must_use = "method returns a new number and does not mutate the original value" ]
525557 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -893,6 +925,8 @@ impl f32 {
893925 /// Returns `ln(1+n)` (natural logarithm) more accurately than if
894926 /// the operations were performed separately.
895927 ///
928+ /// This returns NaN when `n < -1.0`, and negative infinity when `n == -1.0`.
929+ ///
896930 /// # Unspecified precision
897931 ///
898932 /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
@@ -911,6 +945,12 @@ impl f32 {
911945 ///
912946 /// assert!(abs_difference < 1e-10);
913947 /// ```
948+ ///
949+ /// Out-of-range values:
950+ /// ```
951+ /// assert_eq!((-1.0_f32).ln_1p(), f32::NEG_INFINITY);
952+ /// assert!((-2.0_f32).ln_1p().is_nan());
953+ /// ```
914954 #[ doc( alias = "log1p" ) ]
915955 #[ rustc_allow_incoherent_impl]
916956 #[ must_use = "method returns a new number and does not mutate the original value" ]
0 commit comments