mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:20:10 +01:00
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:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user