integer constants can be casted to floats if type is known to be a float

This commit is contained in:
Jakub Doka 2024-11-09 14:02:13 +01:00
parent 63a1c7feb4
commit c657084451
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143

View file

@ -2486,6 +2486,12 @@ impl<'a> Codegen<'a> {
} }
} }
Expr::Bool { value, .. } => Some(self.ci.nodes.new_const_lit(ty::Id::BOOL, value)), Expr::Bool { value, .. } => Some(self.ci.nodes.new_const_lit(ty::Id::BOOL, value)),
Expr::Number { value, .. }
if let Some(ty) = ctx.ty
&& ty.is_float() =>
{
Some(self.ci.nodes.new_const_lit(ty, (value as f64).to_bits() as i64))
}
Expr::Number { value, .. } => Some( Expr::Number { value, .. } => Some(
self.ci.nodes.new_const_lit( self.ci.nodes.new_const_lit(
ctx.ty ctx.ty