Skip to content

Commit 4b2307a

Browse files
John McFarlanevrqq
andcommitted
Reproduce error reported in #991 by vrqq
Co-authored-by: vrqq <vrqq3118@163.com>
1 parent d9e3fee commit 4b2307a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/unit/scaled_integer/rounding/rounding_scaled_integer.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,49 @@ namespace {
8282
static_assert(identical(dest_type{0}, dest_type{source_type{.75}}), "");
8383
static_assert(identical(dest_type{1}, dest_type{source_type{1.}}), "");
8484
}
85+
86+
TEST(rounding_scaled_integer, 991AssignTest)
87+
{
88+
using DecX_2 = cnl::scaled_integer<cnl::rounding_integer<long long>, cnl::power<-2, 10>>;
89+
using DecX_4 = cnl::scaled_integer<cnl::rounding_integer<long long>, cnl::power<-4, 10>>;
90+
91+
DecX_2 n1 = 10.0151;
92+
DecX_2 n2 = 10.0249;
93+
EXPECT_EQ(n1, n2); // 10.02
94+
95+
int64_t xn = (int64_t)n1;
96+
double xm = (double)n2;
97+
EXPECT_EQ(xn, 10);
98+
EXPECT_DOUBLE_EQ(xm, 10.02);
99+
100+
static_assert(std::is_same_v<decltype(n1*n2), DecX_4>);
101+
EXPECT_EQ(n1*n2, DecX_4{100.4004});
102+
EXPECT_DOUBLE_EQ((double)(n1*n2), 100.4004);
103+
104+
n1 += 0.6;
105+
EXPECT_EQ((int)n1, 11);
106+
107+
n1 += 0.38;
108+
EXPECT_EQ(n1, 11);
109+
110+
xn += n1;
111+
xm -= n1;
112+
}
113+
114+
TEST(rounding_scaled_integer, 991CmpTest)
115+
{
116+
using DecX_2 = cnl::scaled_integer<cnl::rounding_integer<long long>, cnl::power<-2, 10>>;
117+
118+
DecX_2 n1;
119+
DecX_2 n2 = 10.019;
120+
DecX_2 n3{20.029};
121+
EXPECT_DOUBLE_EQ((double)n2, 10.02);
122+
EXPECT_DOUBLE_EQ((double)n3, 20.03);
123+
124+
n1 = 3.999; //4.00 instead
125+
n3 = DecX_2(8);
126+
EXPECT_NE(n1, 3.9899999999999999999999999);
127+
EXPECT_EQ(n1, 4.0000000000000000000000001);
128+
EXPECT_EQ(n3, 8);
129+
}
85130
}

0 commit comments

Comments
 (0)