Implement FloatLiteral addition and subtraction (#7621)

Addresses part of issue raised in
https://github.com/carbon-language/carbon-lang/issues/7159 by
implementing float.add & float.sub builtin for FloatLiteralValues

The following code now compiles:

```
let a: f64 = 1.0 + 1.0;
```

Code handles case where operands are both decadic (base 10) and dyadic
(base 2) real literals, with the result being whichever format results
in smaller mantisssa.

File tests assert equality by converting to f128, this can possibly be
improved once CompareWith is implemented for FloatLiteral too.

Assisted-By: Gemini
This commit is contained in:
DavidLoftus
2026-08-18 17:47:58 +00:00
committed by GitHub
parent 0c186053ec
commit 70b6abd6f1
8 changed files with 495 additions and 37 deletions
+7 -4
View File
@@ -729,13 +729,11 @@ constexpr BuiltinInfo FloatNegate = {"float.negate",
// "float.add": float addition.
constexpr BuiltinInfo FloatAdd = {
"float.add",
ValidateSignature<auto(SizedFloatT, SizedFloatT)->SizedFloatT>};
"float.add", ValidateSignature<auto(FloatT, FloatT)->FloatT>};
// "float.sub": float subtraction.
constexpr BuiltinInfo FloatSub = {
"float.sub",
ValidateSignature<auto(SizedFloatT, SizedFloatT)->SizedFloatT>};
"float.sub", ValidateSignature<auto(FloatT, FloatT)->FloatT>};
// "float.mul": float multiplication.
constexpr BuiltinInfo FloatMul = {
@@ -947,6 +945,11 @@ auto BuiltinFunctionKind::IsCompTimeOnly(const File& sem_ir,
case FloatConvert:
case FloatConvertInt:
case FloatNegate:
case FloatAdd:
case FloatSub:
case FloatMul:
case FloatDiv:
case IntConvert:
case IntConvertChar:
case IntConvertFloat: