stabilize const_fn_floating_point_arithmetic

This commit is contained in:
Ralf Jung 2024-08-03 11:17:43 +02:00
parent 43e1145c80
commit 89ad7334e0
9 changed files with 29 additions and 35 deletions

View File

@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)] #![warn(clippy::suboptimal_flops)]
/// Allow suboptimal ops in constant context /// Allow suboptimal ops in constant context

View File

@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)] #![warn(clippy::suboptimal_flops)]
/// Allow suboptimal ops in constant context /// Allow suboptimal ops in constant context

View File

@ -1,5 +1,5 @@
error: manual implementation of `abs` method error: manual implementation of `abs` method
--> tests/ui/floating_point_abs.rs:15:5 --> tests/ui/floating_point_abs.rs:14:5
| |
LL | if num >= 0.0 { num } else { -num } LL | if num >= 0.0 { num } else { -num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
@ -8,43 +8,43 @@ LL | if num >= 0.0 { num } else { -num }
= help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]`
error: manual implementation of `abs` method error: manual implementation of `abs` method
--> tests/ui/floating_point_abs.rs:19:5 --> tests/ui/floating_point_abs.rs:18:5
| |
LL | if 0.0 < num { num } else { -num } LL | if 0.0 < num { num } else { -num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
error: manual implementation of `abs` method error: manual implementation of `abs` method
--> tests/ui/floating_point_abs.rs:23:5 --> tests/ui/floating_point_abs.rs:22:5
| |
LL | if a.a > 0.0 { a.a } else { -a.a } LL | if a.a > 0.0 { a.a } else { -a.a }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`
error: manual implementation of `abs` method error: manual implementation of `abs` method
--> tests/ui/floating_point_abs.rs:27:5 --> tests/ui/floating_point_abs.rs:26:5
| |
LL | if 0.0 >= num { -num } else { num } LL | if 0.0 >= num { -num } else { num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
error: manual implementation of `abs` method error: manual implementation of `abs` method
--> tests/ui/floating_point_abs.rs:31:5 --> tests/ui/floating_point_abs.rs:30:5
| |
LL | if a.a < 0.0 { -a.a } else { a.a } LL | if a.a < 0.0 { -a.a } else { a.a }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`
error: manual implementation of negation of `abs` method error: manual implementation of negation of `abs` method
--> tests/ui/floating_point_abs.rs:35:5 --> tests/ui/floating_point_abs.rs:34:5
| |
LL | if num < 0.0 { num } else { -num } LL | if num < 0.0 { num } else { -num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`
error: manual implementation of negation of `abs` method error: manual implementation of negation of `abs` method
--> tests/ui/floating_point_abs.rs:39:5 --> tests/ui/floating_point_abs.rs:38:5
| |
LL | if 0.0 >= num { num } else { -num } LL | if 0.0 >= num { num } else { -num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`
error: manual implementation of negation of `abs` method error: manual implementation of negation of `abs` method
--> tests/ui/floating_point_abs.rs:44:12 --> tests/ui/floating_point_abs.rs:43:12
| |
LL | a: if a.a >= 0.0 { -a.a } else { a.a }, LL | a: if a.a >= 0.0 { -a.a } else { a.a },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()`

View File

@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)] #![warn(clippy::suboptimal_flops)]
/// Allow suboptimal_ops in constant context /// Allow suboptimal_ops in constant context

View File

@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)] #![warn(clippy::suboptimal_flops)]
/// Allow suboptimal_ops in constant context /// Allow suboptimal_ops in constant context

View File

@ -1,5 +1,5 @@
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:20:13 --> tests/ui/floating_point_mul_add.rs:19:13
| |
LL | let _ = a * b + c; LL | let _ = a * b + c;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, c)` | ^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
@ -8,73 +8,73 @@ LL | let _ = a * b + c;
= help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:21:13 --> tests/ui/floating_point_mul_add.rs:20:13
| |
LL | let _ = a * b - c; LL | let _ = a * b - c;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, -c)` | ^^^^^^^^^ help: consider using: `a.mul_add(b, -c)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:22:13 --> tests/ui/floating_point_mul_add.rs:21:13
| |
LL | let _ = c + a * b; LL | let _ = c + a * b;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, c)` | ^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:23:13 --> tests/ui/floating_point_mul_add.rs:22:13
| |
LL | let _ = c - a * b; LL | let _ = c - a * b;
| ^^^^^^^^^ help: consider using: `a.mul_add(-b, c)` | ^^^^^^^^^ help: consider using: `a.mul_add(-b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:24:13 --> tests/ui/floating_point_mul_add.rs:23:13
| |
LL | let _ = a + 2.0 * 4.0; LL | let _ = a + 2.0 * 4.0;
| ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4.0, a)` | ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4.0, a)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:25:13 --> tests/ui/floating_point_mul_add.rs:24:13
| |
LL | let _ = a + 2. * 4.; LL | let _ = a + 2. * 4.;
| ^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4., a)` | ^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4., a)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:27:13 --> tests/ui/floating_point_mul_add.rs:26:13
| |
LL | let _ = (a * b) + c; LL | let _ = (a * b) + c;
| ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)` | ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:28:13 --> tests/ui/floating_point_mul_add.rs:27:13
| |
LL | let _ = c + (a * b); LL | let _ = c + (a * b);
| ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)` | ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:29:13 --> tests/ui/floating_point_mul_add.rs:28:13
| |
LL | let _ = a * b * c + d; LL | let _ = a * b * c + d;
| ^^^^^^^^^^^^^ help: consider using: `(a * b).mul_add(c, d)` | ^^^^^^^^^^^^^ help: consider using: `(a * b).mul_add(c, d)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:31:13 --> tests/ui/floating_point_mul_add.rs:30:13
| |
LL | let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c; LL | let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c))` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c))`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:32:13 --> tests/ui/floating_point_mul_add.rs:31:13
| |
LL | let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64; LL | let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1234.567_f64.mul_add(45.67834_f64, 0.0004_f64)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1234.567_f64.mul_add(45.67834_f64, 0.0004_f64)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:34:13 --> tests/ui/floating_point_mul_add.rs:33:13
| |
LL | let _ = (a * a + b).sqrt(); LL | let _ = (a * a + b).sqrt();
| ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)` | ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)`
error: multiply and add expressions can be calculated more efficiently and accurately error: multiply and add expressions can be calculated more efficiently and accurately
--> tests/ui/floating_point_mul_add.rs:37:13 --> tests/ui/floating_point_mul_add.rs:36:13
| |
LL | let _ = a - (b * u as f64); LL | let _ = a - (b * u as f64);
| ^^^^^^^^^^^^^^^^^^ help: consider using: `b.mul_add(-(u as f64), a)` | ^^^^^^^^^^^^^^^^^^ help: consider using: `b.mul_add(-(u as f64), a)`

View File

@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)] #![warn(clippy::suboptimal_flops)]
/// Allow suboptimal_flops in constant context /// Allow suboptimal_flops in constant context

View File

@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)] #![warn(clippy::suboptimal_flops)]
/// Allow suboptimal_flops in constant context /// Allow suboptimal_flops in constant context

View File

@ -1,5 +1,5 @@
error: conversion to radians can be done more accurately error: conversion to radians can be done more accurately
--> tests/ui/floating_point_rad.rs:11:13 --> tests/ui/floating_point_rad.rs:10:13
| |
LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0; LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_radians()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_radians()`
@ -8,43 +8,43 @@ LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0;
= help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]`
error: conversion to degrees can be done more accurately error: conversion to degrees can be done more accurately
--> tests/ui/floating_point_rad.rs:12:13 --> tests/ui/floating_point_rad.rs:11:13
| |
LL | let _ = degrees as f64 * 180.0 / std::f64::consts::PI; LL | let _ = degrees as f64 * 180.0 / std::f64::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_degrees()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_degrees()`
error: conversion to degrees can be done more accurately error: conversion to degrees can be done more accurately
--> tests/ui/floating_point_rad.rs:17:13 --> tests/ui/floating_point_rad.rs:16:13
| |
LL | let _ = x * 180f32 / std::f32::consts::PI; LL | let _ = x * 180f32 / std::f32::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()`
error: conversion to degrees can be done more accurately error: conversion to degrees can be done more accurately
--> tests/ui/floating_point_rad.rs:18:13 --> tests/ui/floating_point_rad.rs:17:13
| |
LL | let _ = 90. * 180f64 / std::f64::consts::PI; LL | let _ = 90. * 180f64 / std::f64::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_degrees()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_degrees()`
error: conversion to degrees can be done more accurately error: conversion to degrees can be done more accurately
--> tests/ui/floating_point_rad.rs:19:13 --> tests/ui/floating_point_rad.rs:18:13
| |
LL | let _ = 90.5 * 180f64 / std::f64::consts::PI; LL | let _ = 90.5 * 180f64 / std::f64::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_degrees()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_degrees()`
error: conversion to radians can be done more accurately error: conversion to radians can be done more accurately
--> tests/ui/floating_point_rad.rs:20:13 --> tests/ui/floating_point_rad.rs:19:13
| |
LL | let _ = x * std::f32::consts::PI / 180f32; LL | let _ = x * std::f32::consts::PI / 180f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()`
error: conversion to radians can be done more accurately error: conversion to radians can be done more accurately
--> tests/ui/floating_point_rad.rs:21:13 --> tests/ui/floating_point_rad.rs:20:13
| |
LL | let _ = 90. * std::f32::consts::PI / 180f32; LL | let _ = 90. * std::f32::consts::PI / 180f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_radians()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_radians()`
error: conversion to radians can be done more accurately error: conversion to radians can be done more accurately
--> tests/ui/floating_point_rad.rs:22:13 --> tests/ui/floating_point_rad.rs:21:13
| |
LL | let _ = 90.5 * std::f32::consts::PI / 180f32; LL | let _ = 90.5 * std::f32::consts::PI / 180f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_radians()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_radians()`