@@ -186,11 +186,8 @@ impl f32 {
186186 /// let x = 3.5_f32;
187187 /// let y = -3.5_f32;
188188 ///
189- /// let abs_difference_x = (x.abs() - x).abs();
190- /// let abs_difference_y = (y.abs() - (-y)).abs();
191- ///
192- /// assert!(abs_difference_x <= f32::EPSILON);
193- /// assert!(abs_difference_y <= f32::EPSILON);
189+ /// assert_eq!(x.abs(), x);
190+ /// assert_eq!(y.abs(), y);
194191 ///
195192 /// assert!(f32::NAN.abs().is_nan());
196193 /// ```
@@ -276,10 +273,17 @@ impl f32 {
276273 /// let x = 4.0_f32;
277274 /// let b = 60.0_f32;
278275 ///
279- /// // 100.0
280- /// let abs_difference = (m.mul_add(x, b) - ((m * x) + b)).abs( );
276+ /// assert_eq!(m.mul_add(x, b), 100.0);
277+ /// assert_eq!(m * x + b, 100.0 );
281278 ///
282- /// assert!(abs_difference <= f32::EPSILON);
279+ /// let one_plus_eps = 1.0_f32 + f32::EPSILON;
280+ /// let one_minus_eps = 1.0_f32 - f32::EPSILON;
281+ /// let minus_one = -1.0_f32;
282+ ///
283+ /// // The exact result (1 + eps) * (1 - eps) = 1 - eps * eps.
284+ /// assert_eq!(one_plus_eps.mul_add(one_minus_eps, minus_one), -f32::EPSILON * f32::EPSILON);
285+ /// // Different rounding with the non-fused multiply and add.
286+ /// assert_eq!(one_plus_eps * one_minus_eps + minus_one, 0.0);
283287 /// ```
284288 #[ rustc_allow_incoherent_impl]
285289 #[ must_use = "method returns a new number and does not mutate the original value" ]
@@ -426,9 +430,7 @@ impl f32 {
426430 /// let negative = -4.0_f32;
427431 /// let negative_zero = -0.0_f32;
428432 ///
429- /// let abs_difference = (positive.sqrt() - 2.0).abs();
430- ///
431- /// assert!(abs_difference <= f32::EPSILON);
433+ /// assert_eq!(positive.sqrt(), 2.0);
432434 /// assert!(negative.sqrt().is_nan());
433435 /// assert!(negative_zero.sqrt() == negative_zero);
434436 /// ```
0 commit comments