Support for float <-> float conversions. (#7279)

Implement support for floating-point <-> floating-point type conversions
as described in https://github.com/carbon-language/carbon-lang/pull/820
and https://github.com/carbon-language/carbon-lang/pull/845.
Value-preserving conversions are implicit; narrowing conversions require
explicit `as`.

Assisted-by: Gemini via Antigravity
This commit is contained in:
Richard Smith
2026-06-04 00:33:33 +00:00
committed by GitHub
parent 7fe3e35aec
commit 88c191146d
15 changed files with 976 additions and 11 deletions
@@ -702,6 +702,10 @@ constexpr BuiltinInfo FloatDivAssign = {
"float.div_assign",
ValidateSignature<auto(ByRef<SizedFloatT>, SizedFloatT)->NoReturn>};
// Converts between floating-point types, without checking.
constexpr BuiltinInfo FloatConvert = {"float.convert",
ValidateSignature<auto(FloatT)->FloatU>};
// Converts between floating-point types, with a diagnostic if the value doesn't
// fit.
constexpr BuiltinInfo FloatConvertChecked = {
@@ -859,6 +863,7 @@ auto BuiltinFunctionKind::IsCompTimeOnly(const File& sem_ir,
// Checked conversions are compile-time only.
return true;
case FloatConvert:
case FloatConvertInt:
case IntConvert:
case IntConvertChar: