@@ -186,11 +186,8 @@ impl f32 {
186
186
/// let x = 3.5_f32;
187
187
/// let y = -3.5_f32;
188
188
///
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);
194
191
///
195
192
/// assert!(f32::NAN.abs().is_nan());
196
193
/// ```
@@ -276,10 +273,17 @@ impl f32 {
276
273
/// let x = 4.0_f32;
277
274
/// let b = 60.0_f32;
278
275
///
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 );
281
278
///
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);
283
287
/// ```
284
288
#[ rustc_allow_incoherent_impl]
285
289
#[ must_use = "method returns a new number and does not mutate the original value" ]
@@ -426,9 +430,7 @@ impl f32 {
426
430
/// let negative = -4.0_f32;
427
431
/// let negative_zero = -0.0_f32;
428
432
///
429
- /// let abs_difference = (positive.sqrt() - 2.0).abs();
430
- ///
431
- /// assert!(abs_difference <= f32::EPSILON);
433
+ /// assert_eq!(positive.sqrt(), 2.0);
432
434
/// assert!(negative.sqrt().is_nan());
433
435
/// assert!(negative_zero.sqrt() == negative_zero);
434
436
/// ```
0 commit comments