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
+1 -1
View File
@@ -253,7 +253,7 @@ TEST_F(LexerTest, HandlesNumericLiteral) {
auto token_1_5e9 = token_1_234_567 + 1;
auto value_1_5e9 =
value_stores.reals().Get(buffer.GetRealLiteral(*token_1_5e9));
EXPECT_EQ(value_1_5e9.mantissa.getZExtValue(), 15);
EXPECT_EQ(value_1_5e9.mantissa.getSExtValue(), 15);
EXPECT_EQ(value_1_5e9.exponent.getSExtValue(), 8);
EXPECT_EQ(value_1_5e9.is_decimal, true);
}