mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:31:06 +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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user