Test negative numbers as well

This commit is contained in:
Georg Baum 2015-06-28 11:26:40 +02:00
parent b8eb4fffee
commit 8a27143e72
2 changed files with 99 additions and 46 deletions

View File

@ -27,52 +27,59 @@ void test_uppercase()
void test_formatFPNumber()
{
cout << formatFPNumber(0) << endl;
cout << formatFPNumber(1) << endl;
cout << formatFPNumber(23.42) << endl;
cout << formatFPNumber(1.3754937356458394574047e-20) << endl;
cout << formatFPNumber(1.3754937356458394574047e-19) << endl;
cout << formatFPNumber(1.3754937356458394574047e-18) << endl;
cout << formatFPNumber(1.3754937356458394574047e-17) << endl;
cout << formatFPNumber(1.3754937356458394574047e-16) << endl;
cout << formatFPNumber(1.3754937356458394574047e-15) << endl;
cout << formatFPNumber(1.3754937356458394574047e-14) << endl;
cout << formatFPNumber(1.3754937356458394574047e-13) << endl;
cout << formatFPNumber(1.3754937356458394574047e-12) << endl;
cout << formatFPNumber(1.3754937356458394574047e-11) << endl;
cout << formatFPNumber(1.3754937356458394574047e-10) << endl;
cout << formatFPNumber(1.3754937356458394574047e-9) << endl;
cout << formatFPNumber(1.3754937356458394574047e-8) << endl;
cout << formatFPNumber(1.3754937356458394574047e-7) << endl;
cout << formatFPNumber(1.3754937356458394574047e-6) << endl;
cout << formatFPNumber(1.3754937356458394574047e-5) << endl;
cout << formatFPNumber(1.3754937356458394574047e-4) << endl;
cout << formatFPNumber(1.3754937356458394574047e-3) << endl;
cout << formatFPNumber(1.3754937356458394574047e-2) << endl;
cout << formatFPNumber(1.3754937356458394574047e-1) << endl;
cout << formatFPNumber(1.3754937356458394574047) << endl;
cout << formatFPNumber(1.3754937356458394574047e1) << endl;
cout << formatFPNumber(1.3754937356458394574047e2) << endl;
cout << formatFPNumber(1.3754937356458394574047e3) << endl;
cout << formatFPNumber(1.3754937356458394574047e4) << endl;
cout << formatFPNumber(1.3754937356458394574047e5) << endl;
cout << formatFPNumber(1.3754937356458394574047e6) << endl;
cout << formatFPNumber(1.3754937356458394574047e7) << endl;
cout << formatFPNumber(1.3754937356458394574047e8) << endl;
cout << formatFPNumber(1.3754937356458394574047e9) << endl;
cout << formatFPNumber(1.3754937356458394574047e10) << endl;
cout << formatFPNumber(1.3754937356458394574047e11) << endl;
cout << formatFPNumber(1.3754937356458394574047e12) << endl;
cout << formatFPNumber(1.3754937356458394574047e13) << endl;
cout << formatFPNumber(1.3754937356458394574047e14) << endl;
cout << formatFPNumber(1.3754937356458394574047e15) << endl;
cout << formatFPNumber(1.3754937356458394574047e16) << endl;
cout << formatFPNumber(1.3754937356458394574047e17) << endl;
cout << formatFPNumber(1.3754937356458394574047e18) << endl;
cout << formatFPNumber(1.3754937356458394574047e19) << endl;
cout << formatFPNumber(1.3754937356458394574047e20) << endl;
cout << formatFPNumber(1e-42) << endl;
cout << formatFPNumber(1e42) << endl;
double const numbers[] = {
0,
1,
23.42,
1.3754937356458394574047e-20,
1.3754937356458394574047e-19,
1.3754937356458394574047e-18,
1.3754937356458394574047e-17,
1.3754937356458394574047e-16,
1.3754937356458394574047e-15,
1.3754937356458394574047e-14,
1.3754937356458394574047e-13,
1.3754937356458394574047e-12,
1.3754937356458394574047e-11,
1.3754937356458394574047e-10,
1.3754937356458394574047e-9,
1.3754937356458394574047e-8,
1.3754937356458394574047e-7,
1.3754937356458394574047e-6,
1.3754937356458394574047e-5,
1.3754937356458394574047e-4,
1.3754937356458394574047e-3,
1.3754937356458394574047e-2,
1.3754937356458394574047e-1,
1.3754937356458394574047,
1.3754937356458394574047e1,
1.3754937356458394574047e2,
1.3754937356458394574047e3,
1.3754937356458394574047e4,
1.3754937356458394574047e5,
1.3754937356458394574047e6,
1.3754937356458394574047e7,
1.3754937356458394574047e8,
1.3754937356458394574047e9,
1.3754937356458394574047e10,
1.3754937356458394574047e11,
1.3754937356458394574047e12,
1.3754937356458394574047e13,
1.3754937356458394574047e14,
1.3754937356458394574047e15,
1.3754937356458394574047e16,
1.3754937356458394574047e17,
1.3754937356458394574047e18,
1.3754937356458394574047e19,
1.3754937356458394574047e20,
1e-42,
1e42
};
int const n = sizeof(numbers) / sizeof(numbers[0]);
for (int i = 0; i < n; ++i)
cout << formatFPNumber(numbers[i]) << endl;
for (int i = 0; i < n; ++i)
cout << formatFPNumber(-numbers[i]) << endl;
}
int main()

View File

@ -51,3 +51,49 @@ A
137549373564583952384
0.000000000000000000000000000000000000000001
1000000000000000044885712678075916785549312
-0
-1
-23.42
-0.00000000000000000001375494
-0.0000000000000000001375494
-0.000000000000000001375494
-0.00000000000000001375494
-0.0000000000000001375494
-0.000000000000001375494
-0.00000000000001375494
-0.0000000000001375494
-0.000000000001375494
-0.00000000001375494
-0.0000000001375494
-0.000000001375494
-0.00000001375494
-0.0000001375494
-0.000001375494
-0.00001375494
-0.0001375494
-0.001375494
-0.01375494
-0.1375494
-1.375494
-13.75494
-137.5494
-1375.494
-13754.94
-137549.4
-1375494
-13754937
-137549374
-1375493736
-13754937356
-137549373565
-1375493735646
-13754937356458
-137549373564584
-1375493735645840
-13754937356458394
-137549373564583952
-1375493735645839360
-13754937356458393600
-137549373564583952384
-0.000000000000000000000000000000000000000001
-1000000000000000044885712678075916785549312