2021-06-03 01:41:37 -05:00
|
|
|
use clippy_utils::consts::{
|
2020-03-03 17:52:53 -06:00
|
|
|
constant, constant_simple, Constant,
|
2020-07-14 07:59:59 -05:00
|
|
|
Constant::{Int, F32, F64},
|
2019-12-14 11:28:11 -06:00
|
|
|
};
|
2021-03-25 13:29:11 -05:00
|
|
|
use clippy_utils::diagnostics::span_lint_and_sugg;
|
2021-08-08 09:49:13 -05:00
|
|
|
use clippy_utils::higher;
|
2021-12-17 06:40:22 -06:00
|
|
|
use clippy_utils::{eq_expr_value, get_parent_expr, in_constant, numeric_literal, peel_blocks, sugg};
|
2019-12-14 11:28:11 -06:00
|
|
|
use if_chain::if_chain;
|
|
|
|
use rustc_errors::Applicability;
|
2020-07-14 07:59:59 -05:00
|
|
|
use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, UnOp};
|
2020-02-17 14:56:55 -06:00
|
|
|
use rustc_lint::{LateContext, LateLintPass};
|
2020-03-30 04:02:14 -05:00
|
|
|
use rustc_middle::ty;
|
2020-02-17 13:38:35 -06:00
|
|
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
2020-02-23 22:48:57 -06:00
|
|
|
use rustc_span::source_map::Spanned;
|
|
|
|
|
2020-03-03 17:52:53 -06:00
|
|
|
use rustc_ast::ast;
|
2019-12-14 11:28:11 -06:00
|
|
|
use std::f32::consts as f32_consts;
|
|
|
|
use std::f64::consts as f64_consts;
|
2020-03-03 10:58:37 -06:00
|
|
|
use sugg::Sugg;
|
2019-12-14 11:28:11 -06:00
|
|
|
|
2020-02-23 23:06:55 -06:00
|
|
|
declare_clippy_lint! {
|
2021-07-29 05:16:06 -05:00
|
|
|
/// ### What it does
|
|
|
|
/// Looks for floating-point expressions that
|
2020-02-23 23:06:55 -06:00
|
|
|
/// can be expressed using built-in methods to improve accuracy
|
|
|
|
/// at the cost of performance.
|
|
|
|
///
|
2021-07-29 05:16:06 -05:00
|
|
|
/// ### Why is this bad?
|
|
|
|
/// Negatively impacts accuracy.
|
2020-02-23 23:06:55 -06:00
|
|
|
///
|
2021-07-29 05:16:06 -05:00
|
|
|
/// ### Example
|
2020-02-23 23:06:55 -06:00
|
|
|
/// ```rust
|
|
|
|
/// let a = 3f32;
|
|
|
|
/// let _ = a.powf(1.0 / 3.0);
|
|
|
|
/// let _ = (1.0 + a).ln();
|
|
|
|
/// let _ = a.exp() - 1.0;
|
|
|
|
/// ```
|
|
|
|
///
|
2022-05-28 08:22:59 -05:00
|
|
|
/// Use instead:
|
2020-02-23 23:06:55 -06:00
|
|
|
/// ```rust
|
|
|
|
/// let a = 3f32;
|
|
|
|
/// let _ = a.cbrt();
|
|
|
|
/// let _ = a.ln_1p();
|
|
|
|
/// let _ = a.exp_m1();
|
|
|
|
/// ```
|
2021-12-06 05:33:31 -06:00
|
|
|
#[clippy::version = "1.43.0"]
|
2020-02-23 23:06:55 -06:00
|
|
|
pub IMPRECISE_FLOPS,
|
|
|
|
nursery,
|
|
|
|
"usage of imprecise floating point operations"
|
|
|
|
}
|
|
|
|
|
2019-12-14 11:28:11 -06:00
|
|
|
declare_clippy_lint! {
|
2021-07-29 05:16:06 -05:00
|
|
|
/// ### What it does
|
|
|
|
/// Looks for floating-point expressions that
|
2020-02-17 14:56:55 -06:00
|
|
|
/// can be expressed using built-in methods to improve both
|
|
|
|
/// accuracy and performance.
|
2019-12-14 11:28:11 -06:00
|
|
|
///
|
2021-07-29 05:16:06 -05:00
|
|
|
/// ### Why is this bad?
|
|
|
|
/// Negatively impacts accuracy and performance.
|
2019-12-14 11:28:11 -06:00
|
|
|
///
|
2021-07-29 05:16:06 -05:00
|
|
|
/// ### Example
|
2019-12-14 11:28:11 -06:00
|
|
|
/// ```rust
|
|
|
|
/// use std::f32::consts::E;
|
|
|
|
///
|
2019-12-14 22:10:23 -06:00
|
|
|
/// let a = 3f32;
|
|
|
|
/// let _ = (2f32).powf(a);
|
|
|
|
/// let _ = E.powf(a);
|
|
|
|
/// let _ = a.powf(1.0 / 2.0);
|
|
|
|
/// let _ = a.log(2.0);
|
|
|
|
/// let _ = a.log(10.0);
|
|
|
|
/// let _ = a.log(E);
|
2019-12-15 21:26:44 -06:00
|
|
|
/// let _ = a.powf(2.0);
|
2020-02-23 02:04:11 -06:00
|
|
|
/// let _ = a * 2.0 + 4.0;
|
2020-02-28 00:31:41 -06:00
|
|
|
/// let _ = if a < 0.0 {
|
|
|
|
/// -a
|
|
|
|
/// } else {
|
|
|
|
/// a
|
2020-03-02 01:11:29 -06:00
|
|
|
/// };
|
2020-02-28 00:31:41 -06:00
|
|
|
/// let _ = if a < 0.0 {
|
|
|
|
/// a
|
|
|
|
/// } else {
|
|
|
|
/// -a
|
2020-03-02 01:11:29 -06:00
|
|
|
/// };
|
2019-12-14 11:28:11 -06:00
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// is better expressed as
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use std::f32::consts::E;
|
|
|
|
///
|
2019-12-14 22:10:23 -06:00
|
|
|
/// let a = 3f32;
|
|
|
|
/// let _ = a.exp2();
|
|
|
|
/// let _ = a.exp();
|
|
|
|
/// let _ = a.sqrt();
|
|
|
|
/// let _ = a.log2();
|
|
|
|
/// let _ = a.log10();
|
|
|
|
/// let _ = a.ln();
|
2019-12-15 21:26:44 -06:00
|
|
|
/// let _ = a.powi(2);
|
2020-02-23 02:04:11 -06:00
|
|
|
/// let _ = a.mul_add(2.0, 4.0);
|
2020-02-28 00:31:41 -06:00
|
|
|
/// let _ = a.abs();
|
|
|
|
/// let _ = -a.abs();
|
2019-12-14 11:28:11 -06:00
|
|
|
/// ```
|
2021-12-06 05:33:31 -06:00
|
|
|
#[clippy::version = "1.43.0"]
|
2020-02-17 14:56:55 -06:00
|
|
|
pub SUBOPTIMAL_FLOPS,
|
2019-12-14 11:28:11 -06:00
|
|
|
nursery,
|
2020-02-17 14:56:55 -06:00
|
|
|
"usage of sub-optimal floating point operations"
|
2019-12-14 11:28:11 -06:00
|
|
|
}
|
|
|
|
|
2020-02-23 23:06:55 -06:00
|
|
|
declare_lint_pass!(FloatingPointArithmetic => [
|
|
|
|
IMPRECISE_FLOPS,
|
|
|
|
SUBOPTIMAL_FLOPS
|
|
|
|
]);
|
2019-12-14 11:28:11 -06:00
|
|
|
|
2019-12-16 20:03:51 -06:00
|
|
|
// Returns the specialized log method for a given base if base is constant
|
|
|
|
// and is one of 2, 10 and e
|
2020-06-25 15:41:36 -05:00
|
|
|
fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<&'static str> {
|
2020-07-17 03:47:04 -05:00
|
|
|
if let Some((value, _)) = constant(cx, cx.typeck_results(), base) {
|
2019-12-14 11:28:11 -06:00
|
|
|
if F32(2.0) == value || F64(2.0) == value {
|
2019-12-16 20:03:51 -06:00
|
|
|
return Some("log2");
|
2019-12-14 11:28:11 -06:00
|
|
|
} else if F32(10.0) == value || F64(10.0) == value {
|
2019-12-16 20:03:51 -06:00
|
|
|
return Some("log10");
|
2019-12-14 11:28:11 -06:00
|
|
|
} else if F32(f32_consts::E) == value || F64(f64_consts::E) == value {
|
2019-12-16 20:03:51 -06:00
|
|
|
return Some("ln");
|
2019-12-14 11:28:11 -06:00
|
|
|
}
|
2019-12-16 20:03:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
2019-12-14 11:28:11 -06:00
|
|
|
|
2020-01-04 00:19:13 -06:00
|
|
|
// Adds type suffixes and parenthesis to method receivers if necessary
|
2020-06-25 15:41:36 -05:00
|
|
|
fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Sugg<'a> {
|
2020-01-04 00:19:13 -06:00
|
|
|
let mut suggestion = Sugg::hir(cx, expr, "..");
|
|
|
|
|
2021-02-09 02:15:53 -06:00
|
|
|
if let ExprKind::Unary(UnOp::Neg, inner_expr) = &expr.kind {
|
2021-04-08 10:50:13 -05:00
|
|
|
expr = inner_expr;
|
2020-01-04 00:19:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if_chain! {
|
|
|
|
// if the expression is a float literal and it is unsuffixed then
|
|
|
|
// add a suffix so the suggestion is valid and unambiguous
|
2020-08-03 17:18:29 -05:00
|
|
|
if let ty::Float(float_ty) = cx.typeck_results().expr_ty(expr).kind();
|
2020-01-04 00:19:13 -06:00
|
|
|
if let ExprKind::Lit(lit) = &expr.kind;
|
|
|
|
if let ast::LitKind::Float(sym, ast::LitFloatType::Unsuffixed) = lit.node;
|
|
|
|
then {
|
|
|
|
let op = format!(
|
|
|
|
"{}{}{}",
|
|
|
|
suggestion,
|
|
|
|
// Check for float literals without numbers following the decimal
|
|
|
|
// separator such as `2.` and adds a trailing zero
|
|
|
|
if sym.as_str().ends_with('.') {
|
|
|
|
"0"
|
|
|
|
} else {
|
|
|
|
""
|
|
|
|
},
|
|
|
|
float_ty.name_str()
|
|
|
|
).into();
|
|
|
|
|
|
|
|
suggestion = match suggestion {
|
|
|
|
Sugg::MaybeParen(_) => Sugg::MaybeParen(op),
|
|
|
|
_ => Sugg::NonParen(op)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
suggestion.maybe_par()
|
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_log_base(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
2019-12-16 20:03:51 -06:00
|
|
|
if let Some(method) = get_specialized_log_method(cx, &args[1]) {
|
2019-12-14 11:28:11 -06:00
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
2020-02-17 14:56:55 -06:00
|
|
|
SUBOPTIMAL_FLOPS,
|
2019-12-14 11:28:11 -06:00
|
|
|
expr.span,
|
|
|
|
"logarithm for bases 2, 10 and e can be computed more accurately",
|
|
|
|
"consider using",
|
2020-01-04 00:19:13 -06:00
|
|
|
format!("{}.{}()", Sugg::hir(cx, &args[0], ".."), method),
|
2019-12-14 11:28:11 -06:00
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-20 22:07:03 -06:00
|
|
|
// TODO: Lint expressions of the form `(x + y).ln()` where y > 1 and
|
|
|
|
// suggest usage of `(x + (y - 1)).ln_1p()` instead
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
2020-02-23 22:48:57 -06:00
|
|
|
if let ExprKind::Binary(
|
|
|
|
Spanned {
|
|
|
|
node: BinOpKind::Add, ..
|
|
|
|
},
|
|
|
|
lhs,
|
|
|
|
rhs,
|
|
|
|
) = &args[0].kind
|
|
|
|
{
|
2020-07-17 03:47:04 -05:00
|
|
|
let recv = match (
|
|
|
|
constant(cx, cx.typeck_results(), lhs),
|
|
|
|
constant(cx, cx.typeck_results(), rhs),
|
|
|
|
) {
|
2020-02-23 22:48:57 -06:00
|
|
|
(Some((value, _)), _) if F32(1.0) == value || F64(1.0) == value => rhs,
|
|
|
|
(_, Some((value, _))) if F32(1.0) == value || F64(1.0) == value => lhs,
|
|
|
|
_ => return,
|
|
|
|
};
|
2019-12-14 11:28:11 -06:00
|
|
|
|
2020-02-23 22:48:57 -06:00
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
2020-02-23 23:06:55 -06:00
|
|
|
IMPRECISE_FLOPS,
|
2020-02-23 22:48:57 -06:00
|
|
|
expr.span,
|
|
|
|
"ln(1 + x) can be computed more accurately",
|
|
|
|
"consider using",
|
|
|
|
format!("{}.ln_1p()", prepare_receiver_sugg(cx, recv)),
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
2019-12-14 11:28:11 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 22:29:22 -06:00
|
|
|
// Returns an integer if the float constant is a whole number and it can be
|
|
|
|
// converted to an integer without loss of precision. For now we only check
|
|
|
|
// ranges [-16777215, 16777216) for type f32 as whole number floats outside
|
|
|
|
// this range are lossy and ambiguous.
|
2022-05-07 09:49:19 -05:00
|
|
|
#[expect(clippy::cast_possible_truncation)]
|
2020-02-22 22:29:22 -06:00
|
|
|
fn get_integer_from_float_constant(value: &Constant) -> Option<i32> {
|
2019-12-15 21:26:44 -06:00
|
|
|
match value {
|
2020-02-22 22:29:22 -06:00
|
|
|
F32(num) if num.fract() == 0.0 => {
|
|
|
|
if (-16_777_215.0..16_777_216.0).contains(num) {
|
|
|
|
Some(num.round() as i32)
|
2019-12-15 21:26:44 -06:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
},
|
2020-02-22 22:29:22 -06:00
|
|
|
F64(num) if num.fract() == 0.0 => {
|
|
|
|
if (-2_147_483_648.0..2_147_483_648.0).contains(num) {
|
|
|
|
Some(num.round() as i32)
|
2019-12-15 21:26:44 -06:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
2019-12-14 11:28:11 -06:00
|
|
|
// Check receiver
|
2020-07-17 03:47:04 -05:00
|
|
|
if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[0]) {
|
2020-02-22 22:29:22 -06:00
|
|
|
let method = if F32(f32_consts::E) == value || F64(f64_consts::E) == value {
|
|
|
|
"exp"
|
2019-12-14 11:28:11 -06:00
|
|
|
} else if F32(2.0) == value || F64(2.0) == value {
|
2020-02-22 22:29:22 -06:00
|
|
|
"exp2"
|
2019-12-14 11:28:11 -06:00
|
|
|
} else {
|
|
|
|
return;
|
2020-02-22 22:29:22 -06:00
|
|
|
};
|
2019-12-14 11:28:11 -06:00
|
|
|
|
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
2020-02-17 14:56:55 -06:00
|
|
|
SUBOPTIMAL_FLOPS,
|
2019-12-14 11:28:11 -06:00
|
|
|
expr.span,
|
2019-12-14 22:10:23 -06:00
|
|
|
"exponent for bases 2 and e can be computed more accurately",
|
2019-12-14 11:28:11 -06:00
|
|
|
"consider using",
|
2020-01-04 00:19:13 -06:00
|
|
|
format!("{}.{}()", prepare_receiver_sugg(cx, &args[1]), method),
|
2019-12-14 11:28:11 -06:00
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check argument
|
2020-07-17 03:47:04 -05:00
|
|
|
if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) {
|
2020-02-23 23:06:55 -06:00
|
|
|
let (lint, help, suggestion) = if F32(1.0 / 2.0) == value || F64(1.0 / 2.0) == value {
|
2020-02-22 22:29:22 -06:00
|
|
|
(
|
2020-02-23 23:06:55 -06:00
|
|
|
SUBOPTIMAL_FLOPS,
|
2020-02-22 22:29:22 -06:00
|
|
|
"square-root of a number can be computed more efficiently and accurately",
|
2020-02-23 02:04:11 -06:00
|
|
|
format!("{}.sqrt()", Sugg::hir(cx, &args[0], "..")),
|
2020-02-22 22:29:22 -06:00
|
|
|
)
|
2019-12-14 11:28:11 -06:00
|
|
|
} else if F32(1.0 / 3.0) == value || F64(1.0 / 3.0) == value {
|
2020-02-22 22:29:22 -06:00
|
|
|
(
|
2020-02-23 23:06:55 -06:00
|
|
|
IMPRECISE_FLOPS,
|
2020-02-22 22:29:22 -06:00
|
|
|
"cube-root of a number can be computed more accurately",
|
2020-02-23 02:04:11 -06:00
|
|
|
format!("{}.cbrt()", Sugg::hir(cx, &args[0], "..")),
|
2020-02-22 22:29:22 -06:00
|
|
|
)
|
2019-12-15 21:26:44 -06:00
|
|
|
} else if let Some(exponent) = get_integer_from_float_constant(&value) {
|
2020-02-22 22:29:22 -06:00
|
|
|
(
|
2020-02-23 23:06:55 -06:00
|
|
|
SUBOPTIMAL_FLOPS,
|
2019-12-15 21:26:44 -06:00
|
|
|
"exponentiation with integer powers can be computed more efficiently",
|
2020-02-22 22:29:22 -06:00
|
|
|
format!(
|
|
|
|
"{}.powi({})",
|
|
|
|
Sugg::hir(cx, &args[0], ".."),
|
2020-03-03 10:58:37 -06:00
|
|
|
numeric_literal::format(&exponent.to_string(), None, false)
|
2020-02-23 02:04:11 -06:00
|
|
|
),
|
2020-02-22 22:29:22 -06:00
|
|
|
)
|
2019-12-14 11:28:11 -06:00
|
|
|
} else {
|
|
|
|
return;
|
2020-02-22 22:29:22 -06:00
|
|
|
};
|
2019-12-14 11:28:11 -06:00
|
|
|
|
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
2020-02-23 23:06:55 -06:00
|
|
|
lint,
|
2019-12-14 11:28:11 -06:00
|
|
|
expr.span,
|
|
|
|
help,
|
|
|
|
"consider using",
|
2020-02-22 22:29:22 -06:00
|
|
|
suggestion,
|
2019-12-14 11:28:11 -06:00
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 07:59:59 -05:00
|
|
|
fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
2020-07-17 03:47:04 -05:00
|
|
|
if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) {
|
2020-07-14 07:59:59 -05:00
|
|
|
if value == Int(2) {
|
|
|
|
if let Some(parent) = get_parent_expr(cx, expr) {
|
|
|
|
if let Some(grandparent) = get_parent_expr(cx, parent) {
|
2021-12-01 11:17:50 -06:00
|
|
|
if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, args, _) = grandparent.kind {
|
2020-07-14 07:59:59 -05:00
|
|
|
if method_name.as_str() == "sqrt" && detect_hypot(cx, args).is_some() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let ExprKind::Binary(
|
|
|
|
Spanned {
|
|
|
|
node: BinOpKind::Add, ..
|
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
lhs,
|
|
|
|
rhs,
|
2020-07-14 07:59:59 -05:00
|
|
|
) = parent.kind
|
|
|
|
{
|
|
|
|
let other_addend = if lhs.hir_id == expr.hir_id { rhs } else { lhs };
|
|
|
|
|
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
|
|
|
SUBOPTIMAL_FLOPS,
|
|
|
|
parent.span,
|
2021-05-20 05:30:31 -05:00
|
|
|
"multiply and add expressions can be calculated more efficiently and accurately",
|
2020-07-14 07:59:59 -05:00
|
|
|
"consider using",
|
|
|
|
format!(
|
|
|
|
"{}.mul_add({}, {})",
|
|
|
|
Sugg::hir(cx, &args[0], ".."),
|
|
|
|
Sugg::hir(cx, &args[0], ".."),
|
2021-04-08 10:50:13 -05:00
|
|
|
Sugg::hir(cx, other_addend, ".."),
|
2020-07-14 07:59:59 -05:00
|
|
|
),
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option<String> {
|
|
|
|
if let ExprKind::Binary(
|
|
|
|
Spanned {
|
|
|
|
node: BinOpKind::Add, ..
|
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
add_lhs,
|
|
|
|
add_rhs,
|
2020-07-14 07:59:59 -05:00
|
|
|
) = args[0].kind
|
|
|
|
{
|
|
|
|
// check if expression of the form x * x + y * y
|
|
|
|
if_chain! {
|
2021-04-08 10:50:13 -05:00
|
|
|
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, lmul_lhs, lmul_rhs) = add_lhs.kind;
|
|
|
|
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, rmul_lhs, rmul_rhs) = add_rhs.kind;
|
2020-08-28 09:10:16 -05:00
|
|
|
if eq_expr_value(cx, lmul_lhs, lmul_rhs);
|
|
|
|
if eq_expr_value(cx, rmul_lhs, rmul_rhs);
|
2020-07-14 07:59:59 -05:00
|
|
|
then {
|
2021-12-30 08:10:43 -06:00
|
|
|
return Some(format!("{}.hypot({})", Sugg::hir(cx, lmul_lhs, "..").maybe_par(), Sugg::hir(cx, rmul_lhs, "..")));
|
2020-07-14 07:59:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if expression of the form x.powi(2) + y.powi(2)
|
|
|
|
if_chain! {
|
|
|
|
if let ExprKind::MethodCall(
|
|
|
|
PathSegment { ident: lmethod_name, .. },
|
2021-09-08 09:31:47 -05:00
|
|
|
[largs_0, largs_1, ..],
|
2020-07-14 07:59:59 -05:00
|
|
|
_
|
2021-09-08 09:31:47 -05:00
|
|
|
) = &add_lhs.kind;
|
2020-07-14 07:59:59 -05:00
|
|
|
if let ExprKind::MethodCall(
|
|
|
|
PathSegment { ident: rmethod_name, .. },
|
2021-09-08 09:31:47 -05:00
|
|
|
[rargs_0, rargs_1, ..],
|
2020-07-14 07:59:59 -05:00
|
|
|
_
|
2021-09-08 09:31:47 -05:00
|
|
|
) = &add_rhs.kind;
|
2020-07-14 07:59:59 -05:00
|
|
|
if lmethod_name.as_str() == "powi" && rmethod_name.as_str() == "powi";
|
2021-09-08 09:31:47 -05:00
|
|
|
if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), largs_1);
|
|
|
|
if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), rargs_1);
|
2020-07-14 07:59:59 -05:00
|
|
|
if Int(2) == lvalue && Int(2) == rvalue;
|
|
|
|
then {
|
2021-12-30 08:10:43 -06:00
|
|
|
return Some(format!("{}.hypot({})", Sugg::hir(cx, largs_0, "..").maybe_par(), Sugg::hir(cx, rargs_0, "..")));
|
2020-07-14 07:59:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_hypot(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
|
|
|
if let Some(message) = detect_hypot(cx, args) {
|
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
|
|
|
IMPRECISE_FLOPS,
|
|
|
|
expr.span,
|
|
|
|
"hypotenuse can be computed more accurately",
|
|
|
|
"consider using",
|
|
|
|
message,
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-14 11:28:11 -06:00
|
|
|
// TODO: Lint expressions of the form `x.exp() - y` where y > 1
|
|
|
|
// and suggest usage of `x.exp_m1() - (y - 1)` instead
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
2019-12-14 11:28:11 -06:00
|
|
|
if_chain! {
|
2021-04-08 10:50:13 -05:00
|
|
|
if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, lhs, rhs) = expr.kind;
|
2020-07-17 03:47:04 -05:00
|
|
|
if cx.typeck_results().expr_ty(lhs).is_floating_point();
|
|
|
|
if let Some((value, _)) = constant(cx, cx.typeck_results(), rhs);
|
2019-12-14 11:28:11 -06:00
|
|
|
if F32(1.0) == value || F64(1.0) == value;
|
2021-12-01 11:17:50 -06:00
|
|
|
if let ExprKind::MethodCall(path, [self_arg, ..], _) = &lhs.kind;
|
2021-09-08 09:31:47 -05:00
|
|
|
if cx.typeck_results().expr_ty(self_arg).is_floating_point();
|
2019-12-14 11:28:11 -06:00
|
|
|
if path.ident.name.as_str() == "exp";
|
|
|
|
then {
|
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
2020-02-23 23:06:55 -06:00
|
|
|
IMPRECISE_FLOPS,
|
2019-12-14 11:28:11 -06:00
|
|
|
expr.span,
|
|
|
|
"(e.pow(x) - 1) can be computed more accurately",
|
|
|
|
"consider using",
|
|
|
|
format!(
|
|
|
|
"{}.exp_m1()",
|
2021-09-08 09:31:47 -05:00
|
|
|
Sugg::hir(cx, self_arg, "..")
|
2019-12-14 11:28:11 -06:00
|
|
|
),
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
fn is_float_mul_expr<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> {
|
2020-02-23 02:04:11 -06:00
|
|
|
if_chain! {
|
2021-04-08 10:50:13 -05:00
|
|
|
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, lhs, rhs) = &expr.kind;
|
2020-07-17 03:47:04 -05:00
|
|
|
if cx.typeck_results().expr_ty(lhs).is_floating_point();
|
|
|
|
if cx.typeck_results().expr_ty(rhs).is_floating_point();
|
2020-02-23 02:04:11 -06:00
|
|
|
then {
|
|
|
|
return Some((lhs, rhs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Fix rust-lang/rust-clippy#4735
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
2020-02-23 22:48:57 -06:00
|
|
|
if let ExprKind::Binary(
|
|
|
|
Spanned {
|
|
|
|
node: BinOpKind::Add, ..
|
|
|
|
},
|
|
|
|
lhs,
|
|
|
|
rhs,
|
|
|
|
) = &expr.kind
|
|
|
|
{
|
2020-07-14 07:59:59 -05:00
|
|
|
if let Some(parent) = get_parent_expr(cx, expr) {
|
2021-12-01 11:17:50 -06:00
|
|
|
if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, args, _) = parent.kind {
|
2020-07-14 07:59:59 -05:00
|
|
|
if method_name.as_str() == "sqrt" && detect_hypot(cx, args).is_some() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-23 22:48:57 -06:00
|
|
|
let (recv, arg1, arg2) = if let Some((inner_lhs, inner_rhs)) = is_float_mul_expr(cx, lhs) {
|
|
|
|
(inner_lhs, inner_rhs, rhs)
|
|
|
|
} else if let Some((inner_lhs, inner_rhs)) = is_float_mul_expr(cx, rhs) {
|
|
|
|
(inner_lhs, inner_rhs, lhs)
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
};
|
2020-02-23 02:04:11 -06:00
|
|
|
|
2020-02-23 22:48:57 -06:00
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
|
|
|
SUBOPTIMAL_FLOPS,
|
|
|
|
expr.span,
|
|
|
|
"multiply and add expressions can be calculated more efficiently and accurately",
|
|
|
|
"consider using",
|
|
|
|
format!(
|
|
|
|
"{}.mul_add({}, {})",
|
|
|
|
prepare_receiver_sugg(cx, recv),
|
|
|
|
Sugg::hir(cx, arg1, ".."),
|
|
|
|
Sugg::hir(cx, arg2, ".."),
|
|
|
|
),
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
2020-02-23 02:04:11 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 00:31:41 -06:00
|
|
|
/// Returns true iff expr is an expression which tests whether or not
|
|
|
|
/// test is positive or an expression which tests whether or not test
|
|
|
|
/// is nonnegative.
|
|
|
|
/// Used for check-custom-abs function below
|
2020-06-25 15:41:36 -05:00
|
|
|
fn is_testing_positive(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool {
|
2020-02-28 00:31:41 -06:00
|
|
|
if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind {
|
|
|
|
match op {
|
2020-08-28 09:10:16 -05:00
|
|
|
BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, right) && eq_expr_value(cx, left, test),
|
|
|
|
BinOpKind::Lt | BinOpKind::Le => is_zero(cx, left) && eq_expr_value(cx, right, test),
|
2020-02-28 00:31:41 -06:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 17:52:53 -06:00
|
|
|
/// See [`is_testing_positive`]
|
2020-06-25 15:41:36 -05:00
|
|
|
fn is_testing_negative(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool {
|
2020-02-29 15:46:59 -06:00
|
|
|
if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind {
|
|
|
|
match op {
|
2020-08-28 09:10:16 -05:00
|
|
|
BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, left) && eq_expr_value(cx, right, test),
|
|
|
|
BinOpKind::Lt | BinOpKind::Le => is_zero(cx, right) && eq_expr_value(cx, left, test),
|
2020-02-29 15:46:59 -06:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 00:31:41 -06:00
|
|
|
/// Returns true iff expr is some zero literal
|
2020-06-25 15:41:36 -05:00
|
|
|
fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
2020-07-17 03:47:04 -05:00
|
|
|
match constant_simple(cx, cx.typeck_results(), expr) {
|
2020-03-03 17:52:53 -06:00
|
|
|
Some(Constant::Int(i)) => i == 0,
|
|
|
|
Some(Constant::F32(f)) => f == 0.0,
|
|
|
|
Some(Constant::F64(f)) => f == 0.0,
|
|
|
|
_ => false,
|
2020-02-28 00:31:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 17:52:53 -06:00
|
|
|
/// If the two expressions are negations of each other, then it returns
|
|
|
|
/// a tuple, in which the first element is true iff expr1 is the
|
|
|
|
/// positive expressions, and the second element is the positive
|
|
|
|
/// one of the two expressions
|
|
|
|
/// If the two expressions are not negations of each other, then it
|
|
|
|
/// returns None.
|
2020-06-25 15:41:36 -05:00
|
|
|
fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a>) -> Option<(bool, &'a Expr<'a>)> {
|
2021-02-09 02:15:53 -06:00
|
|
|
if let ExprKind::Unary(UnOp::Neg, expr1_negated) = &expr1.kind {
|
2020-08-28 09:10:16 -05:00
|
|
|
if eq_expr_value(cx, expr1_negated, expr2) {
|
2020-03-03 17:52:53 -06:00
|
|
|
return Some((false, expr2));
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 02:15:53 -06:00
|
|
|
if let ExprKind::Unary(UnOp::Neg, expr2_negated) = &expr2.kind {
|
2020-08-28 09:10:16 -05:00
|
|
|
if eq_expr_value(cx, expr1, expr2_negated) {
|
2020-03-03 17:52:53 -06:00
|
|
|
return Some((true, expr1));
|
2020-02-28 14:40:13 -06:00
|
|
|
}
|
|
|
|
}
|
2020-03-02 00:37:37 -06:00
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_custom_abs(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
2020-03-03 17:52:53 -06:00
|
|
|
if_chain! {
|
2021-12-17 06:40:22 -06:00
|
|
|
if let Some(higher::If { cond, then, r#else: Some(r#else) }) = higher::If::hir(expr);
|
|
|
|
let if_body_expr = peel_blocks(then);
|
|
|
|
let else_body_expr = peel_blocks(r#else);
|
2020-03-03 17:52:53 -06:00
|
|
|
if let Some((if_expr_positive, body)) = are_negated(cx, if_body_expr, else_body_expr);
|
|
|
|
then {
|
|
|
|
let positive_abs_sugg = (
|
|
|
|
"manual implementation of `abs` method",
|
2020-03-02 00:37:37 -06:00
|
|
|
format!("{}.abs()", Sugg::hir(cx, body, "..")),
|
|
|
|
);
|
2020-03-03 17:52:53 -06:00
|
|
|
let negative_abs_sugg = (
|
|
|
|
"manual implementation of negation of `abs` method",
|
2020-03-02 00:37:37 -06:00
|
|
|
format!("-{}.abs()", Sugg::hir(cx, body, "..")),
|
|
|
|
);
|
|
|
|
let sugg = if is_testing_positive(cx, cond, body) {
|
2020-03-03 17:52:53 -06:00
|
|
|
if if_expr_positive {
|
|
|
|
positive_abs_sugg
|
2020-03-02 00:37:37 -06:00
|
|
|
} else {
|
2020-03-03 17:52:53 -06:00
|
|
|
negative_abs_sugg
|
2020-03-02 00:37:37 -06:00
|
|
|
}
|
|
|
|
} else if is_testing_negative(cx, cond, body) {
|
2020-03-03 17:52:53 -06:00
|
|
|
if if_expr_positive {
|
|
|
|
negative_abs_sugg
|
2020-03-02 00:37:37 -06:00
|
|
|
} else {
|
2020-03-03 17:52:53 -06:00
|
|
|
positive_abs_sugg
|
2020-03-02 00:37:37 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
|
|
|
SUBOPTIMAL_FLOPS,
|
|
|
|
expr.span,
|
|
|
|
sugg.0,
|
|
|
|
"try",
|
|
|
|
sugg.1,
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-02-28 00:31:41 -06:00
|
|
|
}
|
|
|
|
|
2020-07-14 07:59:59 -05:00
|
|
|
fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>) -> bool {
|
|
|
|
if_chain! {
|
2021-12-01 11:17:50 -06:00
|
|
|
if let ExprKind::MethodCall(PathSegment { ident: method_name_a, .. }, args_a, _) = expr_a.kind;
|
|
|
|
if let ExprKind::MethodCall(PathSegment { ident: method_name_b, .. }, args_b, _) = expr_b.kind;
|
2020-07-14 07:59:59 -05:00
|
|
|
then {
|
|
|
|
return method_name_a.as_str() == method_name_b.as_str() &&
|
|
|
|
args_a.len() == args_b.len() &&
|
|
|
|
(
|
2021-12-14 23:13:11 -06:00
|
|
|
["ln", "log2", "log10"].contains(&method_name_a.as_str()) ||
|
2020-08-28 09:10:16 -05:00
|
|
|
method_name_a.as_str() == "log" && args_a.len() == 2 && eq_expr_value(cx, &args_a[1], &args_b[1])
|
2020-07-14 07:59:59 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_log_division(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
|
|
|
// check if expression of the form x.logN() / y.logN()
|
|
|
|
if_chain! {
|
|
|
|
if let ExprKind::Binary(
|
|
|
|
Spanned {
|
|
|
|
node: BinOpKind::Div, ..
|
|
|
|
},
|
|
|
|
lhs,
|
|
|
|
rhs,
|
|
|
|
) = &expr.kind;
|
|
|
|
if are_same_base_logs(cx, lhs, rhs);
|
2021-12-01 11:17:50 -06:00
|
|
|
if let ExprKind::MethodCall(_, [largs_self, ..], _) = &lhs.kind;
|
|
|
|
if let ExprKind::MethodCall(_, [rargs_self, ..], _) = &rhs.kind;
|
2020-07-14 07:59:59 -05:00
|
|
|
then {
|
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
|
|
|
SUBOPTIMAL_FLOPS,
|
|
|
|
expr.span,
|
|
|
|
"log base can be expressed more clearly",
|
|
|
|
"consider using",
|
2021-09-08 09:31:47 -05:00
|
|
|
format!("{}.log({})", Sugg::hir(cx, largs_self, ".."), Sugg::hir(cx, rargs_self, ".."),),
|
2020-07-14 07:59:59 -05:00
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
|
|
|
if_chain! {
|
|
|
|
if let ExprKind::Binary(
|
|
|
|
Spanned {
|
|
|
|
node: BinOpKind::Div, ..
|
|
|
|
},
|
|
|
|
div_lhs,
|
|
|
|
div_rhs,
|
|
|
|
) = &expr.kind;
|
|
|
|
if let ExprKind::Binary(
|
|
|
|
Spanned {
|
|
|
|
node: BinOpKind::Mul, ..
|
|
|
|
},
|
|
|
|
mul_lhs,
|
|
|
|
mul_rhs,
|
|
|
|
) = &div_lhs.kind;
|
2020-07-17 03:47:04 -05:00
|
|
|
if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), div_rhs);
|
|
|
|
if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), mul_rhs);
|
2020-07-14 07:59:59 -05:00
|
|
|
then {
|
|
|
|
// TODO: also check for constant values near PI/180 or 180/PI
|
|
|
|
if (F32(f32_consts::PI) == rvalue || F64(f64_consts::PI) == rvalue) &&
|
|
|
|
(F32(180_f32) == lvalue || F64(180_f64) == lvalue)
|
|
|
|
{
|
2021-12-30 08:10:43 -06:00
|
|
|
let mut proposal = format!("{}.to_degrees()", Sugg::hir(cx, mul_lhs, ".."));
|
|
|
|
if_chain! {
|
|
|
|
if let ExprKind::Lit(ref literal) = mul_lhs.kind;
|
|
|
|
if let ast::LitKind::Float(ref value, float_type) = literal.node;
|
|
|
|
if float_type == ast::LitFloatType::Unsuffixed;
|
|
|
|
then {
|
|
|
|
if value.as_str().ends_with('.') {
|
|
|
|
proposal = format!("{}0_f64.to_degrees()", Sugg::hir(cx, mul_lhs, ".."));
|
|
|
|
} else {
|
|
|
|
proposal = format!("{}_f64.to_degrees()", Sugg::hir(cx, mul_lhs, ".."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-14 07:59:59 -05:00
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
|
|
|
SUBOPTIMAL_FLOPS,
|
|
|
|
expr.span,
|
|
|
|
"conversion to degrees can be done more accurately",
|
|
|
|
"consider using",
|
2021-12-30 08:10:43 -06:00
|
|
|
proposal,
|
2020-07-14 07:59:59 -05:00
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
} else if
|
|
|
|
(F32(180_f32) == rvalue || F64(180_f64) == rvalue) &&
|
|
|
|
(F32(f32_consts::PI) == lvalue || F64(f64_consts::PI) == lvalue)
|
|
|
|
{
|
2021-12-30 08:10:43 -06:00
|
|
|
let mut proposal = format!("{}.to_radians()", Sugg::hir(cx, mul_lhs, ".."));
|
|
|
|
if_chain! {
|
|
|
|
if let ExprKind::Lit(ref literal) = mul_lhs.kind;
|
|
|
|
if let ast::LitKind::Float(ref value, float_type) = literal.node;
|
|
|
|
if float_type == ast::LitFloatType::Unsuffixed;
|
|
|
|
then {
|
|
|
|
if value.as_str().ends_with('.') {
|
|
|
|
proposal = format!("{}0_f64.to_radians()", Sugg::hir(cx, mul_lhs, ".."));
|
|
|
|
} else {
|
|
|
|
proposal = format!("{}_f64.to_radians()", Sugg::hir(cx, mul_lhs, ".."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-14 07:59:59 -05:00
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
|
|
|
SUBOPTIMAL_FLOPS,
|
|
|
|
expr.span,
|
|
|
|
"conversion to radians can be done more accurately",
|
|
|
|
"consider using",
|
2021-12-30 08:10:43 -06:00
|
|
|
proposal,
|
2020-07-14 07:59:59 -05:00
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic {
|
|
|
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
2021-12-06 05:33:31 -06:00
|
|
|
// All of these operations are currently not const.
|
|
|
|
if in_constant(cx, expr.hir_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-01 11:17:50 -06:00
|
|
|
if let ExprKind::MethodCall(path, args, _) = &expr.kind {
|
2020-07-17 03:47:04 -05:00
|
|
|
let recv_ty = cx.typeck_results().expr_ty(&args[0]);
|
2019-12-14 11:28:11 -06:00
|
|
|
|
|
|
|
if recv_ty.is_floating_point() {
|
2021-12-14 21:39:23 -06:00
|
|
|
match path.ident.name.as_str() {
|
2019-12-14 11:28:11 -06:00
|
|
|
"ln" => check_ln1p(cx, expr, args),
|
|
|
|
"log" => check_log_base(cx, expr, args),
|
|
|
|
"powf" => check_powf(cx, expr, args),
|
2020-07-14 07:59:59 -05:00
|
|
|
"powi" => check_powi(cx, expr, args),
|
|
|
|
"sqrt" => check_hypot(cx, expr, args),
|
2019-12-14 11:28:11 -06:00
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
check_expm1(cx, expr);
|
2020-02-23 22:48:57 -06:00
|
|
|
check_mul_add(cx, expr);
|
2020-02-28 00:31:41 -06:00
|
|
|
check_custom_abs(cx, expr);
|
2020-07-14 07:59:59 -05:00
|
|
|
check_log_division(cx, expr);
|
|
|
|
check_radians(cx, expr);
|
2019-12-14 11:28:11 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|