@@ -120,18 +120,19 @@ fn check_ln1p(cx: &LateContext<'_, '_>, expr: &Expr, args: &HirVec<Expr>) {
120120// can be converted to an integer without loss
121121// TODO: Add a better check to determine whether the float can be
122122// casted without loss
123- fn get_integer_from_float_constant ( value : Constant ) -> Option < i64 > {
123+ #[ allow( clippy:: cast_possible_truncation) ]
124+ fn get_integer_from_float_constant ( value : & Constant ) -> Option < i64 > {
124125 match value {
125- F32 ( num) if num. trunc ( ) == num => {
126- if num > -16_777_217.0 && num < 16_777_217.0 {
127- Some ( num as i64 )
126+ F32 ( num) if ( num. trunc ( ) - num) . abs ( ) <= std :: f32 :: EPSILON => {
127+ if * num > -16_777_217.0 && * num < 16_777_217.0 {
128+ Some ( num. round ( ) as i64 )
128129 } else {
129130 None
130131 }
131132 } ,
132- F64 ( num) if num. trunc ( ) == num => {
133- if num > -9_007_199_254_740_993.0 && num < 9_007_199_254_740_993.0 {
134- Some ( num as i64 )
133+ F64 ( num) if ( num. trunc ( ) - num) . abs ( ) <= std :: f64 :: EPSILON => {
134+ if * num > -9_007_199_254_740_993.0 && * num < 9_007_199_254_740_993.0 {
135+ Some ( num. round ( ) as i64 )
135136 } else {
136137 None
137138 }
@@ -175,7 +176,7 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr, args: &HirVec<Expr>) {
175176 } else if F32 ( 1.0 / 3.0 ) == value || F64 ( 1.0 / 3.0 ) == value {
176177 help = "cube-root of a number can be computed more accurately" ;
177178 method = "cbrt" ;
178- } else if let Some ( exponent) = get_integer_from_float_constant ( value) {
179+ } else if let Some ( exponent) = get_integer_from_float_constant ( & value) {
179180 span_lint_and_sugg (
180181 cx,
181182 FLOATING_POINT_IMPROVEMENTS ,
0 commit comments