| 90 | public ::testing::WithParamInterface<Bfloat16TestParam> {}; |
| 91 | |
| 92 | TEST_P(Bfloat16Test, TruncateTest) { |
| 93 | bfloat16 truncated = |
| 94 | bfloat16(Eigen::bfloat16_impl::truncate_to_bfloat16((GetParam().input))); |
| 95 | |
| 96 | if (std::isnan(GetParam().input)) { |
| 97 | EXPECT_TRUE(std::isnan(float(truncated)) || std::isinf(float(truncated))); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | EXPECT_EQ(GetParam().expected_truncation, float(truncated)); |
| 102 | |
| 103 | bfloat16 rounded = bfloat16( |
| 104 | Eigen::bfloat16_impl::float_to_bfloat16_rtne<false>((GetParam().input))); |
| 105 | if (std::isnan(GetParam().input)) { |
| 106 | EXPECT_TRUE(std::isnan(float(rounded)) || std::isinf(float(rounded))); |
| 107 | return; |
| 108 | } |
| 109 | EXPECT_EQ(GetParam().expected_rounding, float(rounded)); |
| 110 | } |
| 111 | |
| 112 | INSTANTIATE_TEST_SUITE_P( |
| 113 | Bfloat16Test_Instantiation, Bfloat16Test, |