1
/* Test of conversion float --> unsigned long.
2
$Id: flt2ulng-01.c,v 1.2 2007/12/01 02:12:55 dmix Exp $
13
volatile unsigned long v = 1;
15
PROGMEM const struct { /* Table of test cases. */
21
{ { 0x00000000 }, 0 },
22
{ { 0x80000000 }, 0 },
25
{ { 0x00000001 }, 0 },
26
{ { 0x007fffff }, 0 },
27
{ { 0x00800000 }, 0 },
28
{ { 0x3f7fffff }, 0 },
29
{ { 0x80000001 }, 0 },
30
{ { 0x807fffff }, 0 },
31
{ { 0x80800000 }, 0 },
32
{ { 0xbf7fffff }, 0 },
34
/* all shift values */
35
{ { .fl = 0x1p00 }, 0x00000001 },
36
{ { .fl = 0x1p01 }, 0x00000002 },
37
{ { .fl = 0x1p02 }, 0x00000004 },
38
{ { .fl = 0x1p03 }, 0x00000008 },
39
{ { .fl = 0x1p04 }, 0x00000010 },
40
{ { .fl = 0x1p05 }, 0x00000020 },
41
{ { .fl = 0x1p06 }, 0x00000040 },
42
{ { .fl = 0x1p07 }, 0x00000080 },
43
{ { .fl = 0x1p08 }, 0x00000100 },
44
{ { .fl = 0x1p09 }, 0x00000200 },
45
{ { .fl = 0x1p10 }, 0x00000400 },
46
{ { .fl = 0x1p11 }, 0x00000800 },
47
{ { .fl = 0x1p12 }, 0x00001000 },
48
{ { .fl = 0x1p13 }, 0x00002000 },
49
{ { .fl = 0x1p14 }, 0x00004000 },
50
{ { .fl = 0x1p15 }, 0x00008000 },
51
{ { .fl = 0x1p16 }, 0x00010000 },
52
{ { .fl = 0x1p17 }, 0x00020000 },
53
{ { .fl = 0x1p18 }, 0x00040000 },
54
{ { .fl = 0x1p19 }, 0x00080000 },
55
{ { .fl = 0x1p20 }, 0x00100000 },
56
{ { .fl = 0x1p21 }, 0x00200000 },
57
{ { .fl = 0x1p22 }, 0x00400000 },
58
{ { .fl = 0x1p23 }, 0x00800000 },
59
{ { .fl = 0x1p24 }, 0x01000000 },
60
{ { .fl = 0x1p25 }, 0x02000000 },
61
{ { .fl = 0x1p26 }, 0x04000000 },
62
{ { .fl = 0x1p27 }, 0x08000000 },
63
{ { .fl = 0x1p28 }, 0x10000000 },
64
{ { .fl = 0x1p29 }, 0x20000000 },
65
{ { .fl = 0x1p30 }, 0x40000000 },
66
{ { .fl = 0x1p31 }, 0x80000000 },
69
{ { .fl = 0x1.fffffep+31 }, 0xffffff00 },
71
/* rounding (trunc to zero) */
72
{ { 0x3f7fffff }, 0 },
73
{ { 0x3f800000 }, 1 },
74
{ { 0x3fffffff }, 1 },
75
{ { 0x40000000 }, 2 },
76
{ { 0x403fffff }, 2 },
77
{ { 0x40400000 }, 3 },
78
{ { 0x407fffff }, 3 },
79
{ { .fl = 0x1.000000p+22 }, 0x00400000 },
80
{ { .fl = 0x1.000002p+22 }, 0x00400000 },
82
/* This realization permits negative input, like GCC/x86. */
83
{ { .fl = -0.5 }, 0 },
84
{ { .fl = -1 }, 0xffffffff },
85
{ { .fl = -2 }, 0xfffffffe },
86
{ { .fl = -0x0.7fffffp+32 }, 0x80000100 },
87
{ { .fl = -0x0.800000p+32 }, 0x80000000 },
88
{ { .fl = -0x0.800001p+32 }, 0x7fffff00 },
89
{ { .fl = -0x0.fffffep+32 }, 0x00000200 },
90
{ { .fl = -0x0.ffffffp+32 }, 0x00000100 },
91
{ { .fl = -0x0.800000p+33 }, 0 }, /* overflow */
93
/* Very big numbers (positive and negative). */
94
{ { .fl = 0x0.800000p+56 }, 0 },
95
{ { .fl = 0x0.ffffffp+56 }, 0 },
96
{ { .fl = 0x0.800000p+57 }, 0 },
97
{ { .fl = 0x0.ffffffp+57 }, 0 },
98
{ { 0x7f000000 }, 0 },
99
{ { 0x7f7fffff }, 0 },
100
{ { .fl = -0x0.800000p+56 }, 0 },
101
{ { .fl = -0x0.ffffffp+56 }, 0 },
102
{ { .fl = -0x0.800000p+57 }, 0 },
103
{ { .fl = -0x0.ffffffp+57 }, 0 },
104
{ { 0xff000000 }, 0 },
105
{ { 0xff7fffff }, 0 },
108
{ { 0x7f800000 }, 0 },
109
{ { 0xff800000 }, 0 },
112
{ { 0x7f800001 }, 0 },
113
{ { 0x7fc00000 }, 0 },
114
{ { 0x7fffffff }, 0 },
115
{ { 0xff800001 }, 0 },
116
{ { 0xffc00000 }, 0 },
117
{ { 0xffffffff }, 0 },
120
/* Unlike to GCC/x86 this realization does not shifts value
121
in overflow case. So with not too big numbers the results
124
/* Positive overflow */
125
{ { .fl= 0x0.800000p+33 }, 0 },
126
{ { .fl= 0x0.800001p+33 }, 0 },
127
{ { .fl= 0x0.ffffffp+33 }, 0 },
128
{ { .fl= 0x0.800000p+34 }, 0 },
129
{ { .fl= 0x0.ffffffp+34 }, 0 },
130
{ { .fl= 0x0.800000p+55 }, 0 },
131
{ { .fl= 0x0.ffffffp+55 }, 0 },
133
/* Negative overflow */
134
{ { .fl= -0x0.800000p+33 }, 0 }, /* no overflow */
135
{ { .fl= -0x0.800001p+33 }, 0 },
136
{ { .fl= -0x0.ffffffp+33 }, 0 },
137
{ { .fl= -0x0.800000p+34 }, 0 },
138
{ { .fl= -0x0.ffffffp+34 }, 0 },
139
{ { .fl= -0x0.800000p+55 }, 0 },
140
{ { .fl= -0x0.ffffffp+55 }, 0 },
144
void x_exit (int index)
147
fprintf (stderr, "t[%d]: %lu (%#lx)\n", index - 1, v, v);
149
exit (index ? index : -1);
158
for (i = 0; i < (int) (sizeof(t) / sizeof(t[0])); i++) {
159
x.lo = pgm_read_dword (& t[i].x);
160
z = pgm_read_dword (& t[i].z);