1
/* Test of scanf(): float conversion.
2
$Id: sscanf_flt-f2.c,v 1.1.2.3 2008/03/20 21:42:36 joerg_wunsch Exp $ */
10
# define ASSERT(expr) \
12
if (!(expr)) exit(__LINE__); \
14
# define EXIT(v) exit (v)
15
# if defined(__AVR_ATmega128__)
16
/* ATmega128 has enough RAM for sprintf(), print to 0x2000 in XRAM. */
17
# define PRINTF(f...) sprintf((char *)0x2000, f)
24
# define ASSERT(expr) assert (expr)
25
# define EXIT(v) exit ((v) < 256 ? (v) : 255)
26
# define PRINTF(f...) printf (f)
27
# define sscanf_P sscanf
28
# define memcmp_P memcmp
31
/* Next variables are useful to debug the AVR. */
37
void Check (int line, int expval, int rslt)
41
PRINTF ("\nLine %d: expect= %d, rslt= %d\n", line, expval, rslt);
46
/* The sscanf() is called 4 times: SRAM and FLASH format, 2 values
47
to fill before run. */
48
#define CHECK(expval, ass_expr, str, fmt, ...) \
50
PROGMEM static char fmt_p[] = fmt; \
55
int (* volatile vp)(const char *, const char *, ...); \
57
ASSERT (sizeof(str_s) >= sizeof(str)); \
58
ASSERT (sizeof(fmt_s) >= sizeof(fmt_p)); \
59
strcpy_P (str_s, PSTR(str)); \
60
strcpy_P (fmt_s, fmt_p); \
62
for (FILL = 0; FILL < 4; FILL++) { \
63
memset (&v, FILL, sizeof(v)); \
64
vp = (FILL & 1) ? sscanf_P : sscanf; \
65
i = vp (str_s, (FILL & 1) ? fmt_p : fmt_s, ##__VA_ARGS__); \
66
Check (__LINE__, expval, i); \
73
PROGMEM static const float ones[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
78
v.x[0] == 12345678 && v.x[1] == 0.25
79
&& v.x[2] == 90 && v.x[3] == -0.5,
80
"12345678 .25e0 +9e+01 -0.5E-00",
82
& v.x[0], & v.x[1], & v.x[2], & v.x[3]);
87
!memcmp_P (v.x, ones, 10 * sizeof(float)),
88
"1. 1.0 01 001. 0001.0 00001.00 1.e0 1.00000e000000 1e+00 1e-0",
89
"%e %e %e %e %e %e %e %e %e %e",
90
& v.x[0], & v.x[1], & v.x[2], & v.x[3], & v.x[4],
91
& v.x[5], & v.x[6], & v.x[7], & v.x[8], & v.x[9]);
93
/* Negative exponents. */
96
!memcmp_P (v.x, ones, 10 * sizeof(float)),
107
"%e %e %e %e %e %e %e %e %e %e",
108
& v.x[0], & v.x[1], & v.x[2], & v.x[3], & v.x[4],
109
& v.x[5], & v.x[6], & v.x[7], & v.x[8], & v.x[9]);
113
!memcmp_P (v.x, ones, 10 * sizeof(float)),
116
"10000000000000e-13 "
117
"100000000000000e-14 "
118
"1000000000000000e-15 "
119
"10000000000000000e-16 "
120
"100000000000000000e-17 "
121
"1000000000000000000e-18 "
122
"10000000000000000000e-19 "
123
"100000000000000000000e-20 ",
124
"%e %e %e %e %e %e %e %e %e %e",
125
& v.x[0], & v.x[1], & v.x[2], & v.x[3], & v.x[4],
126
& v.x[5], & v.x[6], & v.x[7], & v.x[8], & v.x[9]);
128
/* Positive exponents. */
131
!memcmp_P (v.x, ones, 10 * sizeof(float)),
142
"%e %e %e %e %e %e %e %e %e %e",
143
& v.x[0], & v.x[1], & v.x[2], & v.x[3], & v.x[4],
144
& v.x[5], & v.x[6], & v.x[7], & v.x[8], & v.x[9]);
148
!memcmp_P (v.x, ones, 10 * sizeof(float)),
152
".00000000000001e14 "
153
".000000000000001e15 "
154
".0000000000000001e16 "
155
".00000000000000001e17 "
156
".000000000000000001e18 "
157
".0000000000000000001e19 "
158
".00000000000000000001e20 ",
159
"%e %e %e %e %e %e %e %e %e %e",
160
& v.x[0], & v.x[1], & v.x[2], & v.x[3], & v.x[4],
161
& v.x[5], & v.x[6], & v.x[7], & v.x[8], & v.x[9]);