File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -740,12 +740,13 @@ impl f32 {
740740 /// # Examples
741741 ///
742742 /// ```
743- /// let x = std::f32::consts::E - 1.0 ;
743+ /// let x = 1e-8_f32 ;
744744 ///
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();
747748 ///
748- /// assert!(abs_difference <= f32::EPSILON );
749+ /// assert!(abs_difference < 1e-10 );
749750 /// ```
750751 #[ must_use = "method returns a new number and does not mutate the original value" ]
751752 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change @@ -742,12 +742,13 @@ impl f64 {
742742 /// # Examples
743743 ///
744744 /// ```
745- /// let x = std::f64::consts::E - 1.0 ;
745+ /// let x = 1e-16_f64 ;
746746 ///
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();
749750 ///
750- /// assert!(abs_difference < 1e-10 );
751+ /// assert!(abs_difference < 1e-20 );
751752 /// ```
752753 #[ must_use = "method returns a new number and does not mutate the original value" ]
753754 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments