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