Fix ecvt/fcvt issues w.r.t. value==0 and ndigit==0 (#1282)

Before this commit, cosmopolitan had some issues with handling arguments
of 0 and signs, such as returning an incorrect sign when the input value
== -0.0, and incorrectly handling ndigit == 0 on fcvt (ndigit determines
the amount of digits *after* the radix character on fcvt, thus the parts
before it still must be outputted before fcvt's job is completely done).

This patch fixes these issues, and adds tests with corresponding inputs.
This commit is contained in:
Gabriel Ravier 2024-09-08 03:08:11 +02:00 committed by GitHub
parent dc579b79cd
commit f882887178
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 4 deletions

View file

@ -31,3 +31,38 @@ TEST(fcvt, test) {
ASSERT_EQ(1, decpt);
ASSERT_EQ(0, sign);
}
TEST(ecvt, minus0) {
int decpt = 110000000, sign = 110000000;
ASSERT_STREQ("00000", ecvt(-0.0, 5, &decpt, &sign));
ASSERT_LE(0, decpt);
ASSERT_GE(1, decpt);
ASSERT_EQ(1, sign);
}
TEST(ecvt, minus0ndigits0) {
int decpt = 110000000, sign = 110000000;
ASSERT_STREQ("", ecvt(-0.0, 0, &decpt, &sign));
ASSERT_LE(0, decpt);
ASSERT_GE(1, decpt);
ASSERT_EQ(1, sign);
}
TEST(fcvt, ndigits0) {
int decpt = 110000000, sign = 110000000;
ASSERT_STREQ("1", fcvt(0.6, 0, &decpt, &sign));
ASSERT_EQ(1, decpt);
ASSERT_EQ(0, sign);
}
TEST(fcvt, minus0ndigits0) {
int decpt = 110000000, sign = 110000000;
ASSERT_STREQ("", fcvt(-0.0, 0, &decpt, &sign));
ASSERT_LE(0, decpt);
ASSERT_GE(1, decpt);
ASSERT_EQ(1, sign);
}