[llvm] [APFloat] Add APFloat support for E8M0 type (PR #107127)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 04:02:00 PDT 2024


================
@@ -5790,6 +5872,46 @@ TEST(APFloatTest, Float8E4M3FNExhaustive) {
   }
 }
 
+TEST(APFloatTest, Float8E8M0FNExhaustive) {
+  // Test each of the 256 Float8E8M0FN values.
+  for (int i = 0; i < 256; i++) {
+    APFloat test(APFloat::Float8E8M0FN(), APInt(8, i));
+    SCOPED_TRACE("i=" + std::to_string(i));
+
+    // isLargest
+    if (i == 254) {
+      EXPECT_TRUE(test.isLargest());
+      EXPECT_EQ(abs(test).convertToDouble(), 0x1.0p127);
+    } else {
+      EXPECT_FALSE(test.isLargest());
+    }
+
+    // isSmallest
+    if (i == 0) {
+      EXPECT_TRUE(test.isSmallest());
+      EXPECT_EQ(abs(test).convertToDouble(), 0x1.0p-127);
+    } else {
+      EXPECT_FALSE(test.isSmallest());
+    }
+
+    // convert to Double
+    bool losesInfo;
+    std::string prefix = "0x1.0p";
+    std::string val = std::to_string(i - 127); // 127 is the bias
+    std::string final_str = prefix + val;
----------------
arsenm wrote:

SmallString? 

https://github.com/llvm/llvm-project/pull/107127


More information about the llvm-commits mailing list