Skip to content

Commit

Permalink
Update tests for new printf
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterymath committed Feb 19, 2024
1 parent 3ea0141 commit 929c39c
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 1 deletion.
1 change: 1 addition & 0 deletions SingleSource/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ if(ARCH STREQUAL "MOS")
target_link_libraries(FloatPrecision PRIVATE printf_flt)
target_link_libraries(StructModifyTest PRIVATE printf_flt)
target_link_libraries(byval-alignment PRIVATE printf_flt)
target_link_libraries(printf_float PRIVATE printf_flt)
else()
if (COMPILER_HAS_MATRIX_FLAG)
set_property(TARGET matrix-types-spec PROPERTY LINK_OPTIONS -fenable-matrix)
Expand Down
105 changes: 105 additions & 0 deletions SingleSource/UnitTests/printf_float.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include <float.h>
#include <stdio.h>

int main(void) {
// Basic
printf("%f\n", 1.0);
printf("%f\n", 2.0);
printf("%f\n", 3.0);
printf("%f\n", 0.5);

// 2^53-1; maximum number of 1s.
printf("%f\n", 9007199254740991.0);

printf("%f\n", DBL_MAX);
printf("%.1500f\n", DBL_MIN);

// Zero
printf("%f\n", 0.0);

// Round to even
printf("%.0f\n", 1.1);
printf("%.0f\n", 1.9);
printf("%.0f\n", 1.5);
printf("%.0f\n", 2.5);
printf("%.0f\n", 0.9);

// Alt
printf("%#.0f\n", 0.0);

// Negative
printf("%f\n", -1.0);
printf("%f\n", -0.0);

// Infinity
printf("%f\n", 1.0/0);
printf("%f\n", -1.0/0);
printf("%F\n", 1.0/0);
printf("%4f\n", 1.0/0);
printf("%04f\n", 1.0/0);
printf("% f\n", 1.0/0);
printf("%+f\n", 1.0/0);

// NaN
printf("%f\n", 0.0/0);

// Plus
printf("%+f\n", 1.0);

// Space
printf("% f\n", 1.0);

// Width
printf("%1f\n", 0.0);
printf("%9f\n", 0.0);
printf("%9f\n", 1.0);
printf("%10f\n", 10.0);
printf("%2.f\n", 0.0);
printf("%#3.f\n", 0.0);
printf("%+3.f\n", 0.0);
printf("% 3.f\n", 0.0);

// Zero
printf("%09f\n", 0.0);

// Minus
printf("%-9fx\n", 0.0);

// Exp
printf("%e\n", 0.0);
printf("%e\n", 1.0);
printf("%e\n", 2.0);
printf("%e\n", 0.5);
printf("%e\n", 10.0);
printf("%e\n", 1e10);
printf("%e\n", 1e100);
printf("%.e\n", 15.0);
printf("%E\n", 0.0);

// Exp width
printf("%6.e\n", 0.0);
printf("%7.e\n", 1e100);

// Generic
printf("%g\n", 0.0);
printf("%#g\n", 0.0);
printf("%g\n", 1e-4);
printf("%g\n", 1e-5);
printf("%g\n", 1e5);
printf("%g\n", 1e6);
printf("%g\n", 0.0001234567);
printf("%g\n", 0.00001234567);

// Hex
printf("%a\n", 0.0);
printf("%A\n", 0.0);
printf("%#a\n", 0.0);
printf("%a\n", 1.0);
printf("%a\n", 0x1p128);
printf("%.6a\n", 0.0);
printf("%a\n", 0.1234567);
printf("%6a\n", 0.0);
printf("%7a\n", 0.0);
printf("%7a\n", 0x1p10);
printf("%8a\n", 0x1p10);
}
67 changes: 67 additions & 0 deletions SingleSource/UnitTests/printf_float.reference_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
1.000000
2.000000
3.000000
0.500000
9007199254740991.000000
179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000
0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022250738585072013830902327173324040642192159804623318305533274168872044348139181958542831590125110205640673397310358110051524341615534601088560123853777188211307779935320023304796101474425836360719215650469425037342083752508066506166581589487204911799685916396485006359087701183048747997808877537499494515804516050509153998565824708186451135379358049921159810857660519924333521143523901487956996095912888916029926415110634663133936634775865130293717620473256317814856643508721228286376420448468114076139114770628016898532441100241614474216185671661505401542850847167529019031613227788967297073731233340869889831750678388469260927739779728586596549410913690954061364675687023986783152906809846172109246253967285156250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0.000000
1
2
2
2
1
0.
-1.000000
-0.000000
inf
-inf
INF
inf
inf
inf
+inf
nan
+1.000000
1.000000
0.000000
0.000000
1.000000
10.000000
0
0.
+0
0
00.000000
0.000000 x
0.000000e+00
1.000000e+00
2.000000e+00
5.000000e-01
1.000000e+01
1.000000e+10
1.000000e+100
2e+01
0.000000E+00
0e+00
1e+100
0
0.00000
0.0001
1e-05
100000
1e+06
0.000123457
1.23457e-05
0x0p+0
0X0P+0
0x0.p+0
0x1p+0
0x1p+128
0x0.000000p+0
0x1.f9adbb8f8da72p-4
0x0p+0
0x0p+0
0x1p+10
0x1p+10
exit 0
50 changes: 50 additions & 0 deletions SingleSource/UnitTests/printf_int.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <stdio.h>

int main(void) {
// Basic
printf("%d\n", 0);
printf("%d\n", 6502);

// Precision
printf("%.d\n", 0);
printf("%.0d\n", 0);
printf("%.1d\n", 0);
printf("%.2d\n", 0);
printf("%.*d\n", -5, 0);
printf("%.3d\n", 42);
printf("%.2d\n", 42);
printf("%.1d\n", 42);
printf("%.d\n", 42);

// Minus
printf("%.3d\n", -42);

// Plus
printf("%+.3d\n", 42);
printf("%+.3d\n", -42);
printf("%+.3d\n", -42);

// Space
printf("% d\n", 0);
printf("% d\n", -1);
printf("% +d\n", 1);

// Alternate
printf("%#o\n", 042);
printf("%#.o\n", 042);
printf("%#x\n", 0xab);
printf("%#X\n", 0xab);

// Padding
printf("%2dx\n", 0);
printf("%-2dx\n", 0);
printf("%2dx\n", 123);
printf("%3dx\n", -1);
printf("%+3dx\n", 1);
printf("% 3dx\n", 1);
printf("%#4xx\n", 1);

// Zero
printf("%02dx\n", 0);
printf("%-02dx\n", 0);
}
32 changes: 32 additions & 0 deletions SingleSource/UnitTests/printf_int.reference_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
0
6502


0
00
0
042
42
42
42
-042
+042
-042
-042
0
-1
+1
042
042
0xab
0XAB
0x
0 x
123x
-1x
+1x
1x
0x1x
00x
0 x
exit 0
2 changes: 1 addition & 1 deletion SingleSource/UnitTests/printf_p.reference_output
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ABCD
0xabcd
exit 0

0 comments on commit 929c39c

Please sign in to comment.