Implement Core.Negate for float literals (#7616)

Addresses part of issue raised in #7159 by implementing float.negate
builtin for FloatLiteralValues

The following code now compiles:

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

To achieve this I switch the mantissa from being unsigned to signed.
Lexed literals within source file will still always be unsigned, however
it is now possible to create negative FloatLiteralValue constants. Main
non-local changes this causes is:

- All llvm::APInt parsing / printing calls flipped isSigned param
- Zero extension replaced with sign extension
- getActiveBits() replaced with getSignificantBits() for min bit width
calculation
This commit is contained in:
DavidLoftus
2026-08-13 20:28:42 +00:00
committed by GitHub
parent 2784f33221
commit 54b7f1345a
9 changed files with 222 additions and 119 deletions
+2 -2
View File
@@ -724,8 +724,8 @@ constexpr BuiltinInfo IntGreaterEq = {
"int.greater_eq", ValidateSignature<auto(IntT, IntU)->Bool>};
// "float.negate": float negation.
constexpr BuiltinInfo FloatNegate = {
"float.negate", ValidateSignature<auto(SizedFloatT)->SizedFloatT>};
constexpr BuiltinInfo FloatNegate = {"float.negate",
ValidateSignature<auto(FloatT)->FloatT>};
// "float.add": float addition.
constexpr BuiltinInfo FloatAdd = {