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 @@ -719,12 +719,13 @@ impl f32 {
719719 /// # Examples
720720 ///
721721 /// ```
722- /// let x = 6.0f32 ;
722+ /// let x = 1e-8_f32 ;
723723 ///
724- /// // e^(ln(6)) - 1
725- /// let abs_difference = (x.ln().exp_m1() - 5.0).abs();
724+ /// // for very small x, e^x is approximately 1 + x + x^2 / 2
725+ /// let approx = x + x * x / 2.0;
726+ /// let abs_difference = (x.exp_m1() - approx).abs();
726727 ///
727- /// assert!(abs_difference <= f32::EPSILON );
728+ /// assert!(abs_difference < 1e-10 );
728729 /// ```
729730 #[ must_use = "method returns a new number and does not mutate the original value" ]
730731 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change @@ -721,12 +721,13 @@ impl f64 {
721721 /// # Examples
722722 ///
723723 /// ```
724- /// let x = 7.0_f64 ;
724+ /// let x = 1e-16_f64 ;
725725 ///
726- /// // e^(ln(7)) - 1
727- /// let abs_difference = (x.ln().exp_m1() - 6.0).abs();
726+ /// // for very small x, e^x is approximately 1 + x + x^2 / 2
727+ /// let approx = x + x * x / 2.0;
728+ /// let abs_difference = (x.exp_m1() - approx).abs();
728729 ///
729- /// assert!(abs_difference < 1e-10 );
730+ /// assert!(abs_difference < 1e-20 );
730731 /// ```
731732 #[ must_use = "method returns a new number and does not mutate the original value" ]
732733 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments