1
/* Test of float comparison, Inf.
2
$Id: cmp-02.c,v 1.1 2007/02/05 21:35:58 dmix Exp $
13
PROGMEM const struct { /* Table of test cases. */
15
unsigned char ne; /* x != y */
16
unsigned char lt; /* x < y */
17
unsigned char le; /* x <= y */
18
unsigned char eq; /* x == y */
19
unsigned char ge; /* x >= y */
20
unsigned char gt; /* x > y */
23
/* 0.0 and Inf, all signes */
24
{ { 0x00000000 }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
25
{ { 0x80000000 }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
26
{ { 0x00000000 }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
27
{ { 0x80000000 }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
29
/* nonzero and +Inf */
30
{ { 0xff7fffff }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
31
{ { 0x80800000 }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
32
{ { 0x807fffff }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
33
{ { 0x80000001 }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
34
{ { 0x00000001 }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
35
{ { 0x007fffff }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
36
{ { 0x00800000 }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
37
{ { 0x7f7fffff }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
39
/* nonzero and -Inf */
40
{ { 0xff7fffff }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
41
{ { 0x80800000 }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
42
{ { 0x807fffff }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
43
{ { 0x80000001 }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
44
{ { 0x00000001 }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
45
{ { 0x007fffff }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
46
{ { 0x00800000 }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
47
{ { 0x7f7fffff }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
49
/* +Inf and nonzero */
50
{ { 0x7f800000 }, { 0xff7fffff }, 1, 0, 0, 0, 1, 1 },
51
{ { 0x7f800000 }, { 0x80800000 }, 1, 0, 0, 0, 1, 1 },
52
{ { 0x7f800000 }, { 0x807fffff }, 1, 0, 0, 0, 1, 1 },
53
{ { 0x7f800000 }, { 0x80000001 }, 1, 0, 0, 0, 1, 1 },
54
{ { 0x7f800000 }, { 0x00000001 }, 1, 0, 0, 0, 1, 1 },
55
{ { 0x7f800000 }, { 0x007fffff }, 1, 0, 0, 0, 1, 1 },
56
{ { 0x7f800000 }, { 0x00800000 }, 1, 0, 0, 0, 1, 1 },
57
{ { 0x7f800000 }, { 0x7f7fffff }, 1, 0, 0, 0, 1, 1 },
59
/* -Inf and nonzero */
60
{ { 0xff800000 }, { 0xff7fffff }, 1, 1, 1, 0, 0, 0 },
61
{ { 0xff800000 }, { 0x80800000 }, 1, 1, 1, 0, 0, 0 },
62
{ { 0xff800000 }, { 0x807fffff }, 1, 1, 1, 0, 0, 0 },
63
{ { 0xff800000 }, { 0x80000001 }, 1, 1, 1, 0, 0, 0 },
64
{ { 0xff800000 }, { 0x00000001 }, 1, 1, 1, 0, 0, 0 },
65
{ { 0xff800000 }, { 0x007fffff }, 1, 1, 1, 0, 0, 0 },
66
{ { 0xff800000 }, { 0x00800000 }, 1, 1, 1, 0, 0, 0 },
67
{ { 0xff800000 }, { 0x7f7fffff }, 1, 1, 1, 0, 0, 0 },
69
/* Inf and Inf, all signes */
70
{ { 0x7f800000 }, { 0x7f800000 }, 0, 0, 1, 1, 1, 0 },
71
{ { 0xff800000 }, { 0xff800000 }, 0, 0, 1, 1, 1, 0 },
72
{ { 0xff800000 }, { 0x7f800000 }, 1, 1, 1, 0, 0, 0 },
73
{ { 0x7f800000 }, { 0xff800000 }, 1, 0, 0, 0, 1, 1 },
76
unsigned char cmpno = 255; /* to debug */
78
void x_exit (int index, unsigned char no)
81
fprintf (stderr, "t[%d]: no= %d\n", index - 1, no);
84
exit (index ? index : -1);
87
volatile union lofl_u x, y;
93
for (i = 0; i < (int) (sizeof(t) / sizeof(t[0])); i++) {
94
x.lo = pgm_read_dword (& t[i].x);
95
y.lo = pgm_read_dword (& t[i].y);
96
if ((x.fl != y.fl) != pgm_read_byte (& t[i].ne))
98
if ((x.fl < y.fl) != pgm_read_byte (& t[i].lt))
100
if ((x.fl <= y.fl) != pgm_read_byte (& t[i].le))
102
if ((x.fl == y.fl) != pgm_read_byte (& t[i].eq))
104
if ((x.fl >= y.fl) != pgm_read_byte (& t[i].ge))
106
if ((x.fl > y.fl) != pgm_read_byte (& t[i].gt))