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
+8
View File
@@ -140,6 +140,14 @@ impl CharLiteral as SubWith(Self) where .Result = IntLiteral {
// Operations for FloatLiteral. These need to be here because FloatLiteral has no
// associated library of its own.
impl FloatLiteral as AddWith(Self) where .Result = Self {
fn Op(self, other: Self) -> Self = "float.add";
}
impl FloatLiteral as Negate where .Result = Self {
fn Op(self) -> Self = "float.negate";
}
impl FloatLiteral as SubWith(Self) where .Result = Self {
fn Op(self, other: Self) -> Self = "float.sub";
}