Skip to content

Commit 6a1380c

Browse files
authored
Rollup merge of #50572 - frewsxcv:frewsxcv-fma, r=sfackler
Clarify in the docs that `mul_add` is not always faster. Fixes #49842. Other resources: - https://users.rust-lang.org/t/why-does-the-mul-add-method-produce-a-more-accurate-result-with-better-performance/1626 - https://en.wikipedia.org/wiki/Multiply%E2%80%93accumulate_operation
2 parents 932029e + 0ba1c10 commit 6a1380c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/libstd/f32.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ impl f32 {
195195
}
196196

197197
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
198-
/// error. This produces a more accurate result with better performance than
199-
/// a separate multiplication operation followed by an add.
198+
/// error, yielding a more accurate result than an unfused multiply-add.
199+
///
200+
/// Using `mul_add` can be more performant than an unfused multiply-add if
201+
/// the target architecture has a dedicated `fma` CPU instruction.
200202
///
201203
/// ```
202204
/// use std::f32;

src/libstd/f64.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ impl f64 {
173173
}
174174

175175
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
176-
/// error. This produces a more accurate result with better performance than
177-
/// a separate multiplication operation followed by an add.
176+
/// error, yielding a more accurate result than an unfused multiply-add.
177+
///
178+
/// Using `mul_add` can be more performant than an unfused multiply-add if
179+
/// the target architecture has a dedicated `fma` CPU instruction.
178180
///
179181
/// ```
180182
/// let m = 10.0_f64;

0 commit comments

Comments
 (0)