Skip to content

Commit baf2511

Browse files
committed
feat: add more tests
Signed-off-by: krishna2803 <[email protected]>
1 parent 66800a7 commit baf2511

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

libc/test/src/stdfix/BitsFxTest.h

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ class BitsFxTest : public LIBC_NAMESPACE::testing::Test {
2121
static constexpr T one_fourth = FXRep::ONE_FOURTH();
2222
static constexpr T eps = FXRep::EPS();
2323

24-
// (0.42)_10 =
25-
// (0.0110101110000101000111101011100001010001111010111000010100011110)_2 =
26-
// (0.0x6b851eb851eb851e)_16
27-
static constexpr unsigned long long zero_point_forty_two =
28-
0x6b851eb851eb851eULL;
24+
static constexpr T zero_point_six_eight_seven_five_t = 0.6875;
25+
26+
static constexpr T negative_zero_point_six_eight_seven_five_t = -0.6875;
27+
28+
// an arbitrarily chosen special number
29+
static constexpr T special_num_t = 10.71875;
30+
31+
static constexpr T negative_special_num_t = -10.71875;
2932

3033
public:
3134
typedef XType (*BitsFxFunc)(T);
@@ -40,11 +43,46 @@ class BitsFxTest : public LIBC_NAMESPACE::testing::Test {
4043

4144
// (0.6875)_10 = (0.1011)_2
4245
EXPECT_EQ(static_cast<XType>(11ULL << (FXRep::FRACTION_LEN - 4)),
43-
func(0.6875));
46+
func(zero_point_six_eight_seven_five_t));
47+
48+
if constexpr (FXRep::SIGN_LEN > 0)
49+
EXPECT_EQ(static_cast<XType>(-(11ULL << (FXRep::FRACTION_LEN - 4))),
50+
func(negative_zero_point_six_eight_seven_five_t));
51+
52+
if constexpr (FXRep::INTEGRAL_LEN > 0) {
53+
if (static_cast<int>(max) >= 11)
54+
switch (FXRep::FRACTION_LEN) {
55+
case 7:
56+
EXPECT_EQ(static_cast<XType>(1372), func(special_num_t));
57+
break;
58+
case 15:
59+
EXPECT_EQ(static_cast<XType>(351232), func(special_num_t));
60+
break;
61+
case 23:
62+
EXPECT_EQ(static_cast<XType>(89915392), func(special_num_t));
63+
break;
64+
default:
65+
break;
66+
}
67+
}
4468

45-
EXPECT_EQ(
46-
static_cast<XType>(zero_point_forty_two >> (64 - FXRep::FRACTION_LEN)),
47-
func(0.42));
69+
if constexpr (FXRep::SIGN_LEN > 0 && FXRep::INTEGRAL_LEN > 0) {
70+
if (static_cast<int>(min) <= -11)
71+
switch (FXRep::FRACTION_LEN) {
72+
case 7:
73+
EXPECT_EQ(static_cast<XType>(-1372), func(negative_special_num_t));
74+
break;
75+
case 15:
76+
EXPECT_EQ(static_cast<XType>(-351232), func(negative_special_num_t));
77+
break;
78+
case 23:
79+
EXPECT_EQ(static_cast<XType>(-89915392),
80+
func(negative_special_num_t));
81+
break;
82+
default:
83+
break;
84+
}
85+
}
4886
}
4987
};
5088

0 commit comments

Comments
 (0)