profile
viewpoint

Ask questionsmanual_mul_add suggests broken code

let x = f64::from(32) + 2.0 * 4.0;

clippy suggests

warning: consider using mul_add() for better numerical precision
 --> src/main.rs:3:10
  |
3 |     let x = f64::from(32) + 2.0 * 4.0;
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `2.0.mul_add(4.0, f64::from(32))`
  |

but

	 let x = 2.0.mul_add(4.0, f64::from(32));

does not compile:

error[E0599]: no method named `mul_add` found for type `{float}` in the current scope
 --> src/main.rs:4:15
  |
4 |      let x = 2.0.mul_add(4.0, f64::from(32));
  |                  ^^^^^^^ method not found in `{float}`

rust-lang/rust-clippy

Answer questions matthiaskrgr

If my code is f64::from(32) + 2. * 4.;, clippy suggests 2..mul_add(4., f64::from(32)), the 2..mul_add( also looks kinda questionable imo.

useful!
source:https://uonfu.com/
Github User Rank List