Skip to content

Commit

Permalink
stabilize const_fn_floating_point_arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 22, 2024
1 parent 43e1145 commit 89ad733
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 35 deletions.
1 change: 0 additions & 1 deletion tests/ui/floating_point_abs.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]

/// Allow suboptimal ops in constant context
Expand Down
1 change: 0 additions & 1 deletion tests/ui/floating_point_abs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]

/// Allow suboptimal ops in constant context
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/floating_point_abs.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
Expand All @@ -8,43 +8,43 @@ LL | if num >= 0.0 { num } else { -num }
= help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]`

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 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`

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 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`

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 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`

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 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`

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 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`

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 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`

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 },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/floating_point_mul_add.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]

/// Allow suboptimal_ops in constant context
Expand Down
1 change: 0 additions & 1 deletion tests/ui/floating_point_mul_add.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]

/// Allow suboptimal_ops in constant context
Expand Down
26 changes: 13 additions & 13 deletions tests/ui/floating_point_mul_add.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
Expand All @@ -8,73 +8,73 @@ LL | let _ = a * b + c;
= help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]`

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;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, -c)`

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;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, c)`

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;
| ^^^^^^^^^ help: consider using: `a.mul_add(-b, c)`

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;
| ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4.0, a)`

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.;
| ^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4., a)`

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;
| ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)`

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);
| ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)`

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;
| ^^^^^^^^^^^^^ help: consider using: `(a * b).mul_add(c, d)`

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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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
--> 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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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
--> tests/ui/floating_point_mul_add.rs:34:13
--> tests/ui/floating_point_mul_add.rs:33:13
|
LL | let _ = (a * a + b).sqrt();
| ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)`

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);
| ^^^^^^^^^^^^^^^^^^ help: consider using: `b.mul_add(-(u as f64), a)`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/floating_point_rad.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]

/// Allow suboptimal_flops in constant context
Expand Down
1 change: 0 additions & 1 deletion tests/ui/floating_point_rad.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]

/// Allow suboptimal_flops in constant context
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/floating_point_rad.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_radians()`
Expand All @@ -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)]`

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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_degrees()`

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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()`

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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_degrees()`

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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_degrees()`

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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()`

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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_radians()`

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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_radians()`
Expand Down

0 comments on commit 89ad733

Please sign in to comment.