File tree 2 files changed +10
-8
lines changed
2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -740,12 +740,13 @@ impl f32 {
740
740
/// # Examples
741
741
///
742
742
/// ```
743
- /// let x = std::f32::consts::E - 1.0 ;
743
+ /// let x = 1e-8_f32 ;
744
744
///
745
- /// // ln(1 + (e - 1)) == ln(e) == 1
746
- /// let abs_difference = (x.ln_1p() - 1.0).abs();
745
+ /// // for very small x, ln(1 + x) is approximately x - x^2 / 2
746
+ /// let approx = x - x * x / 2.0;
747
+ /// let abs_difference = (x.ln_1p() - approx).abs();
747
748
///
748
- /// assert!(abs_difference <= f32::EPSILON );
749
+ /// assert!(abs_difference < 1e-10 );
749
750
/// ```
750
751
#[ must_use = "method returns a new number and does not mutate the original value" ]
751
752
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change @@ -742,12 +742,13 @@ impl f64 {
742
742
/// # Examples
743
743
///
744
744
/// ```
745
- /// let x = std::f64::consts::E - 1.0 ;
745
+ /// let x = 1e-16_f64 ;
746
746
///
747
- /// // ln(1 + (e - 1)) == ln(e) == 1
748
- /// let abs_difference = (x.ln_1p() - 1.0).abs();
747
+ /// // for very small x, ln(1 + x) is approximately x - x^2 / 2
748
+ /// let approx = x - x * x / 2.0;
749
+ /// let abs_difference = (x.ln_1p() - approx).abs();
749
750
///
750
- /// assert!(abs_difference < 1e-10 );
751
+ /// assert!(abs_difference < 1e-20 );
751
752
/// ```
752
753
#[ must_use = "method returns a new number and does not mutate the original value" ]
753
754
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments