mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
More fixed precision tests
This commit is contained in:
parent
dd6cc0e6ac
commit
97619e27a2
@ -588,7 +588,7 @@ struct fixed_handler {
|
||||
}
|
||||
|
||||
digits::result on_digit(char digit, uint64_t divisor, uint64_t remainder,
|
||||
uint64_t error, int& exp, bool integral) {
|
||||
uint64_t error, int, bool integral) {
|
||||
FMT_ASSERT(remainder < divisor, "");
|
||||
buf[size++] = digit;
|
||||
if (size != precision) return digits::more;
|
||||
@ -601,7 +601,6 @@ struct fixed_handler {
|
||||
FMT_ASSERT(error == 1 && divisor > 2, "");
|
||||
}
|
||||
auto dir = get_round_direction(divisor, remainder, error);
|
||||
// TODO: test rounding
|
||||
if (dir != up) return dir == down ? digits::done : digits::error;
|
||||
++buf[size - 1];
|
||||
for (int i = size - 1; i > 0 && buf[i] > '9'; --i) {
|
||||
@ -610,7 +609,7 @@ struct fixed_handler {
|
||||
}
|
||||
if (buf[0] > '9') {
|
||||
buf[0] = '1';
|
||||
++exp;
|
||||
buf[size++] = '0';
|
||||
}
|
||||
return digits::done;
|
||||
}
|
||||
|
@ -1476,7 +1476,13 @@ TEST(FormatterTest, PrecisionRounding) {
|
||||
EXPECT_EQ("0.001", format("{:.3f}", 0.0005));
|
||||
EXPECT_EQ("0.001", format("{:.3f}", 0.00149));
|
||||
EXPECT_EQ("0.002", format("{:.3f}", 0.0015));
|
||||
EXPECT_EQ("1.000", format("{:.3f}", 0.9999));
|
||||
EXPECT_EQ("0.00123", format("{:.3}", 0.00123));
|
||||
// Trigger rounding error in Grisu by a carefully chosen number.
|
||||
auto n = 3788512123356.985352;
|
||||
char buffer[64];
|
||||
sprintf(buffer, "%f", n);
|
||||
EXPECT_EQ(buffer, format("{:f}", n));
|
||||
}
|
||||
|
||||
TEST(FormatterTest, FormatNaN) {
|
||||
|
Loading…
Reference in New Issue
Block a user