-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtests.c
125 lines (121 loc) · 3.26 KB
/
tests.c
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
/* Testing Code */
#include <limits.h>
/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
/* This header is separate from features.h so that the compiler can
include it implicitly at the start of every compilation. It must
not itself include <features.h> or any other header that includes
<features.h> because the implicit include comes before any feature
test macros that may be defined in a source file before it first
explicitly includes a system header. GCC knows the name of this
header in order to preinclude it. */
/* glibc's intent is to support the IEC 559 math functionality, real
and complex. If the GCC (4.9 and later) predefined macros
specifying compiler intent are available, use them to determine
whether the overall intent is to support these features; otherwise,
presume an older compiler has intent to support these features and
define these macros by default. */
/* wchar_t uses Unicode 9.0.0. Version 9.0 of the Unicode Standard is
synchronized with ISO/IEC 10646:2014, fourth edition, plus
Amd. 1 and Amd. 2 and 273 characters from forthcoming 10646, fifth edition.
(Amd. 2 was published 2016-05-01,
see https://www.iso.org/obp/ui/#iso:std:iso-iec:10646:ed-4:v1:amd:2:v1:en) */
/* We do not support C11 <threads.h>. */
int test_abs(int x) {
return (x < 0) ? -x : x;
}
int test_bitAnd(int x, int y)
{
return x&y;
}
int test_bitMask(int highbit, int lowbit)
{
int result = 0;
int i;
for (i = lowbit; i <= highbit; i++)
result |= 1 << i;
return result;
}
int test_bitXor(int x, int y)
{
return x^y;
}
int test_conditional(int x, int y, int z)
{
return x?y:z;
}
int test_evenBits(void) {
int result = 0;
int i;
for (i = 0; i < 32; i+=2)
result |= 1<<i;
return result;
}
int test_isEqual(int x, int y)
{
return x == y;
}
int test_isLess(int x, int y)
{
return x < y;
}
int test_isNegative(int x) {
return x < 0;
}
int test_isNonZero(int x)
{
return x!=0;
}
int test_isPower2(int x) {
int i;
for (i = 0; i < 31; i++) {
if (x == 1<<i)
return 1;
}
return 0;
}
int test_leastBitPos(int x) {
int mask = 1;
if (x == 0)
return 0;
while (!(mask & x)) {
mask = mask << 1;
}
return mask;
}
int test_logicalNeg(int x)
{
return !x;
}
int test_reverseBytes(int x)
{
union U {
int result;
char byte[4];
};
union U u;
int temp;
u.result = x;
temp = u.byte[0];
u.byte[0] = u.byte[3];
u.byte[3] = temp;
temp = u.byte[1];
u.byte[1] = u.byte[2];
u.byte[2] = temp;
return u.result;
}
int test_sum3(int x, int y, int z)
{
return x+y+z;
}