about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorTrevor Spiteri <tspiteri@ieee.org>2020-09-23 12:02:49 +0200
committerTrevor Spiteri <tspiteri@ieee.org>2020-09-23 12:02:49 +0200
commit50d3ddcb0cbc36f782fa5939d1ef24422f6902d4 (patch)
tree4aadee59a7a5e6f782986ccc4c1460436362c32a /library/std/src
parent37ce212f1f0a009a181d3a0a27dbd52505d4ac07 (diff)
downloadrust-50d3ddcb0cbc36f782fa5939d1ef24422f6902d4.tar.gz
rust-50d3ddcb0cbc36f782fa5939d1ef24422f6902d4.zip
make ln_1p examples more representative of use
With this commit, the examples for ln_1p would fail if (x + 1.0).ln()
is used instead of x.ln_1p().
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/f32.rs9
-rw-r--r--library/std/src/f64.rs9
2 files changed, 10 insertions, 8 deletions
diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs
index cd9065b3a21..ed975c42879 100644
--- a/library/std/src/f32.rs
+++ b/library/std/src/f32.rs
@@ -740,12 +740,13 @@ impl f32 {
     /// # Examples
     ///
     /// ```
-    /// let x = std::f32::consts::E - 1.0;
+    /// let x = 1e-8_f32;
     ///
-    /// // ln(1 + (e - 1)) == ln(e) == 1
-    /// let abs_difference = (x.ln_1p() - 1.0).abs();
+    /// // for very small x, ln(1 + x) is approximately x - x^2 / 2
+    /// let approx = x - x * x / 2.0;
+    /// let abs_difference = (x.ln_1p() - approx).abs();
     ///
-    /// assert!(abs_difference <= f32::EPSILON);
+    /// 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")]
diff --git a/library/std/src/f64.rs b/library/std/src/f64.rs
index e412f89432c..8d0a85e056f 100644
--- a/library/std/src/f64.rs
+++ b/library/std/src/f64.rs
@@ -742,12 +742,13 @@ impl f64 {
     /// # Examples
     ///
     /// ```
-    /// let x = std::f64::consts::E - 1.0;
+    /// let x = 1e-16_f64;
     ///
-    /// // ln(1 + (e - 1)) == ln(e) == 1
-    /// let abs_difference = (x.ln_1p() - 1.0).abs();
+    /// // for very small x, ln(1 + x) is approximately x - x^2 / 2
+    /// let approx = x - x * x / 2.0;
+    /// let abs_difference = (x.ln_1p() - approx).abs();
     ///
-    /// assert!(abs_difference < 1e-10);
+    /// assert!(abs_difference < 1e-20);
     /// ```
     #[must_use = "method returns a new number and does not mutate the original value"]
     #[stable(feature = "rust1", since = "1.0.0")]