File: testClassification.cpp

package info (click to toggle)
openexr 1.2.2-4.3
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 15,508 kB
  • ctags: 3,410
  • sloc: cpp: 40,009; sh: 8,399; makefile: 345
file content (170 lines) | stat: -rw-r--r-- 4,085 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <testClassification.h>
#include <half.h>
#include <iostream>
#include <assert.h>


using namespace std;

namespace {

void
testClass (half h,
	   bool finite,
	   bool normalized,
	   bool denormalized,
	   bool zero,
	   bool nan,
	   bool infinity,
	   bool negative)
{
    cout.width (15);
    cout.precision (8);

    cout << h << "    ";
    printBits (cout, h);
    cout << "    ";

    if (h.isFinite())
	cout << "finite ";

    if (h.isNormalized())
	cout << "normalized ";

    if (h.isDenormalized())
	cout << "denormalized ";

    if (h.isZero())
	cout << "zero ";

    if (h.isNan())
	cout << "nan ";

    if (h.isInfinity())
	cout << "infinity ";

    if (h.isNegative())
	cout << "negative ";

    cout << endl;

    assert (h.isFinite() == finite);
    assert (h.isNormalized() == normalized);
    assert (h.isDenormalized() == denormalized);
    assert (h.isZero() == zero);
    assert (h.isNan() == nan);
    assert (h.isInfinity() == infinity);
    assert (h.isNegative() == negative);
}


float
floatPosInfinity ()
{
    half::uif x;
    x.i = 0x7f800000;
    return x.f;
}


float
floatNegInfinity ()
{
    half::uif x;
    x.i = 0xff800000;
    return x.f;
}


float
floatPosQNan1 ()
{
    half::uif x;
    x.i = 0x7fffffff;
    return x.f;
}


float
floatNegQNan1 ()
{
    half::uif x;
    x.i = 0xffffffff;
    return x.f;
}


float
floatPosQNan2 ()
{
    half::uif x;
    x.i = 0x7fd55555;
    return x.f;
}


float
floatNegQNan2 ()
{
    half::uif x;
    x.i = 0xffd55555;
    return x.f;
}

} // namespace


void
testClassification()
{
    cout << "classification of bit patterns\n\n";

    //
    //					fini norm deno zero nan  inf  neg
    //

    testClass (0.0,			1,   0,   0,   1,   0,   0,   0);

    testClass (1.0,			1,   1,   0,   0,   0,   0,   0);
    testClass (1.0 + HALF_EPSILON,	1,   1,   0,   0,   0,   0,   0);
    testClass (HALF_MIN,		1,   0,   1,   0,   0,   0,   0);
    testClass (HALF_MIN + HALF_MIN,	1,   0,   1,   0,   0,   0,   0);
    testClass (HALF_NRM_MIN,		1,   1,   0,   0,   0,   0,   0);
    testClass (HALF_NRM_MIN + HALF_MIN,	1,   1,   0,   0,   0,   0,   0);
    testClass (HALF_NRM_MIN - HALF_MIN,	1,   0,   1,   0,   0,   0,   0);
    testClass (2.0,			1,   1,   0,   0,   0,   0,   0);
    testClass (3.0,			1,   1,   0,   0,   0,   0,   0);
    testClass (0.1,			1,   1,   0,   0,   0,   0,   0);
    testClass (0.2,			1,   1,   0,   0,   0,   0,   0);
    testClass (0.3,			1,   1,   0,   0,   0,   0,   0);
    testClass (HALF_MAX,		1,   1,   0,   0,   0,   0,   0);
    testClass (floatPosInfinity(),	0,   0,   0,   0,   0,   1,   0);
    testClass (floatPosQNan1(),		0,   0,   0,   0,   1,   0,   0);
    testClass (floatPosQNan2(),		0,   0,   0,   0,   1,   0,   0);

    testClass (-1.0,			1,   1,   0,   0,   0,   0,   1);
    testClass (-1.0 - HALF_EPSILON,	1,   1,   0,   0,   0,   0,   1);
    testClass (-HALF_MIN,		1,   0,   1,   0,   0,   0,   1);
    testClass (-HALF_MIN - HALF_MIN,	1,   0,   1,   0,   0,   0,   1);
    testClass (-HALF_NRM_MIN,		1,   1,   0,   0,   0,   0,   1);
    testClass (-HALF_NRM_MIN - HALF_MIN,1,   1,   0,   0,   0,   0,   1);
    testClass (-HALF_NRM_MIN + HALF_MIN,1,   0,   1,   0,   0,   0,   1);
    testClass (-2.0,			1,   1,   0,   0,   0,   0,   1);
    testClass (-3.0,			1,   1,   0,   0,   0,   0,   1);
    testClass (-0.1,			1,   1,   0,   0,   0,   0,   1);
    testClass (-0.2,			1,   1,   0,   0,   0,   0,   1);
    testClass (-0.3,			1,   1,   0,   0,   0,   0,   1);
    testClass (-HALF_MAX,		1,   1,   0,   0,   0,   0,   1);
    testClass (floatNegInfinity(),	0,   0,   0,   0,   0,   1,   1);
    testClass (floatNegQNan1(),		0,   0,   0,   0,   1,   0,   1);
    testClass (floatNegQNan2(),		0,   0,   0,   0,   1,   0,   1);

    cout << "\n";

    testClass (half::posInf(),		0,   0,   0,   0,   0,   1,   0);
    testClass (half::negInf(),		0,   0,   0,   0,   0,   1,   1);
    testClass (half::qNan(),		0,   0,   0,   0,   1,   0,   0);
    testClass (half::sNan(),		0,   0,   0,   0,   1,   0,   0);

    cout << "ok\n\n" << flush;
}