~ubuntu-branches/ubuntu/wily/avr-libc/wily-proposed

« back to all changes in this revision

Viewing changes to tests/simulate/fplib/cmp-02.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2009-10-31 11:52:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091031115210-crjd42sn6ezrj52c
Tags: 1:1.6.7-1
* New upstream relese (closes: #544030)
* Added lintian overrides (closes: #553265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Test of float comparison, Inf.
2
 
   $Id: cmp-02.c,v 1.1 2007/02/05 21:35:58 dmix Exp $
3
 
 */
4
 
#include <stdio.h>
5
 
#include <stdlib.h>
6
 
#include "progmem.h"
7
 
 
8
 
union lofl_u {
9
 
    long lo;
10
 
    float fl;
11
 
};
12
 
 
13
 
PROGMEM const struct {          /* Table of test cases. */
14
 
    union lofl_u x, y;
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  */
21
 
} t[] = {
22
 
 
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  },
28
 
    
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  },
38
 
 
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  },
48
 
 
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  },
58
 
 
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  },
68
 
 
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  },
74
 
};
75
 
 
76
 
unsigned char cmpno = 255;              /* to debug     */
77
 
 
78
 
void x_exit (int index, unsigned char no)
79
 
{
80
 
#ifndef __AVR__
81
 
    fprintf (stderr, "t[%d]: no= %d\n", index - 1, no);
82
 
#endif
83
 
    cmpno = no;
84
 
    exit (index ? index : -1);
85
 
}
86
 
 
87
 
volatile union lofl_u x, y;
88
 
 
89
 
int main ()
90
 
{
91
 
    int i;
92
 
    
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))
97
 
            x_exit (i+1, 1);
98
 
        if ((x.fl < y.fl)  != pgm_read_byte (& t[i].lt))
99
 
            x_exit (i+1, 2);
100
 
        if ((x.fl <= y.fl) != pgm_read_byte (& t[i].le))
101
 
            x_exit (i+1, 3);
102
 
        if ((x.fl == y.fl) != pgm_read_byte (& t[i].eq))
103
 
            x_exit (i+1, 4);
104
 
        if ((x.fl >= y.fl) != pgm_read_byte (& t[i].ge))
105
 
            x_exit (i+1, 5);
106
 
        if ((x.fl > y.fl)  != pgm_read_byte (& t[i].gt))
107
 
            x_exit (i+1, 6);
108
 
    }
109
 
    return 0;
110
 
}