diff options
| author | Trevor Spiteri <tspiteri@ieee.org> | 2020-09-23 12:01:25 +0200 |
|---|---|---|
| committer | Trevor Spiteri <tspiteri@ieee.org> | 2020-09-23 12:01:25 +0200 |
| commit | 37ce212f1f0a009a181d3a0a27dbd52505d4ac07 (patch) | |
| tree | e48c66ec4be284c9c8ebaaa4b6256264b479b0df /library/std/src | |
| parent | f6d59207ad56e24a2bfefa3544de48a0f6491363 (diff) | |
| download | rust-37ce212f1f0a009a181d3a0a27dbd52505d4ac07.tar.gz rust-37ce212f1f0a009a181d3a0a27dbd52505d4ac07.zip | |
make exp_m1 examples more representative of use
With this commit, the examples for exp_m1 would fail if x.exp() - 1.0 is used instead of x.exp_m1().
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/f32.rs | 9 | ||||
| -rw-r--r-- | library/std/src/f64.rs | 9 |
2 files changed, 10 insertions, 8 deletions
diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs index 59c2da5273b..cd9065b3a21 100644 --- a/library/std/src/f32.rs +++ b/library/std/src/f32.rs @@ -719,12 +719,13 @@ impl f32 { /// # Examples /// /// ``` - /// let x = 6.0f32; + /// let x = 1e-8_f32; /// - /// // e^(ln(6)) - 1 - /// let abs_difference = (x.ln().exp_m1() - 5.0).abs(); + /// // for very small x, e^x is approximately 1 + x + x^2 / 2 + /// let approx = x + x * x / 2.0; + /// let abs_difference = (x.exp_m1() - 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 bd094bdb55d..e412f89432c 100644 --- a/library/std/src/f64.rs +++ b/library/std/src/f64.rs @@ -721,12 +721,13 @@ impl f64 { /// # Examples /// /// ``` - /// let x = 7.0_f64; + /// let x = 1e-16_f64; /// - /// // e^(ln(7)) - 1 - /// let abs_difference = (x.ln().exp_m1() - 6.0).abs(); + /// // for very small x, e^x is approximately 1 + x + x^2 / 2 + /// let approx = x + x * x / 2.0; + /// let abs_difference = (x.exp_m1() - 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")] |
