Add support for f16, f64, f128. (#5952)

Generalize the f64 support to support other sizes. Also provide interop
support for `float`, `_Float16`, and `__float128`.

Also lay some groundwork for non-standard floating-point types, though
we don't have any syntax to name them yet.
This commit is contained in:
Richard Smith
2025-08-14 01:14:40 +00:00
committed by GitHub
parent cfe5599144
commit b851e8c423
27 changed files with 826 additions and 379 deletions
+10 -9
View File
@@ -1071,15 +1071,16 @@ static auto MapBuiltinType(Context& context, SemIR::LocId loc_id,
return type_expr;
}
// TODO: Handle integer types that map to named aliases.
} else if (type.isDoubleType()) {
// TODO: Handle other floating point types when Carbon supports fN where N
// != 64.
CARBON_CHECK(ast_context.getTypeSize(qual_type) == 64);
CARBON_CHECK(ast_context.hasSameType(qual_type, ast_context.DoubleTy));
return ExprAsType(
context, Parse::NodeId::None,
MakeFloatTypeLiteral(context, Parse::NodeId::None,
SemIR::FloatKind::None, context.ints().Add(64)));
} else if (type.isFloatingPoint()) {
if (type.isFloat16Type() || type.isFloat32Type() || type.isDoubleType() ||
type.isFloat128Type()) {
return ExprAsType(
context, Parse::NodeId::None,
MakeFloatTypeLiteral(
context, Parse::NodeId::None,
context.ints().Add(ast_context.getTypeSize(qual_type))));
}
// TODO: Handle floating-point types that map to named aliases.
}
return {.inst_id = SemIR::TypeInstId::None, .type_id = SemIR::TypeId::None};