mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add builtins for basic float operations (#3897)
Adds support for unary `-` and binary `+`, `-`, `*`, `/` for floating point types. Real literals are now transformed to `llvm::APFloat`s during the check phase into the `FloatLiteral` instruction. This PR likely collides a bit with #3892 and might need to be updated when that one is merged.
This commit is contained in:
@@ -59,6 +59,24 @@ TEST(ValueStore, Real) {
|
||||
EXPECT_THAT(real2.is_decimal, Eq(real2_copy.is_decimal));
|
||||
}
|
||||
|
||||
TEST(ValueStore, Float) {
|
||||
llvm::APFloat float1(1.0);
|
||||
llvm::APFloat float2(2.0);
|
||||
|
||||
SharedValueStores value_stores;
|
||||
FloatId id1 = value_stores.floats().Add(float1);
|
||||
FloatId id2 = value_stores.floats().Add(float2);
|
||||
|
||||
ASSERT_TRUE(id1.is_valid());
|
||||
ASSERT_TRUE(id2.is_valid());
|
||||
EXPECT_THAT(id1, Not(Eq(id2)));
|
||||
|
||||
EXPECT_THAT(value_stores.floats().Get(id1).compare(float1),
|
||||
Eq(llvm::APFloatBase::cmpEqual));
|
||||
EXPECT_THAT(value_stores.floats().Get(id2).compare(float2),
|
||||
Eq(llvm::APFloatBase::cmpEqual));
|
||||
}
|
||||
|
||||
TEST(ValueStore, String) {
|
||||
std::string a = "a";
|
||||
std::string b = "b";
|
||||
|
||||
Reference in New Issue
Block a user