Skip to content

Commit

Permalink
Add is_float_literal utility
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Jan 19, 2025
1 parent 2220806 commit 3002063
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,17 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool {
false
}

/// Checks whether the given expression is a constant literal of the given value.
pub fn is_float_literal(expr: &Expr<'_>, value: f64) -> bool {
if let ExprKind::Lit(spanned) = expr.kind
&& let LitKind::Float(v, _) = spanned.node
{
v.as_str().parse() == Ok(value)
} else {
false
}
}

/// Returns `true` if the given `Expr` has been coerced before.
///
/// Examples of coercions can be found in the Nomicon at
Expand Down

0 comments on commit 3002063

Please sign in to comment.