1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2002
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /* 01/02/2003   Port to LTP	avenkat@us.ibm.com */
21 /* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
22 
23 /*
24  * NAME
25  *	abs -- absolute integer value
26  *
27  * CALLS
28  *	abs(3)
29  *
30  * ALGORITHM
31  *	Check with variables.  Also most neg value as listed
32  *	on man page.
33  *
34  * RESTRICTIONS
35  *	considered a long time - estimate this one
36  */
37 #define _GNU_SOURCE 1
38 
39 #include <stdio.h>		/* needed by testhead.h         */
40 #include <stdlib.h>
41 #include <unistd.h>
42 #include <ctype.h>
43 #include <math.h>
44 #include <errno.h>
45 #include <values.h>
46 
47 /*****	LTP Port	*****/
48 
49 #include "test.h"
50 #define FAILED 0
51 #define PASSED 1
52 
53 char *TCID = "abs01";
54 int local_flag = PASSED;
55 int block_number;
56 int errno;
57 FILE *temp;
58 int TST_TOTAL = 1;
59 
60 static void setup(void);
61 static int blenter(void);
62 static int blexit(void);
63 
64 /********************************/
65 
66 /*--------------------------------------------------------------*/
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69 	register long long i;
70 	register int j, k, l, m;
71 
72 	setup();		/* temp file is now open        */
73 /*--------------------------------------------------------------*/
74 	blenter();
75 
76 	i = llabs(MININT) + (long long)MININT;
77 
78 	if (i != 0) {
79 		fprintf(temp, "abs of minimum integer failed.");
80 		local_flag = FAILED;
81 	}
82 
83 	blexit();
84 /*--------------------------------------------------------------*/
85 	blenter();
86 
87 	i = llabs(0);
88 	if (i != 0) {
89 		fprintf(temp, "abs(0) failed, returned %lld\n", i);
90 		local_flag = FAILED;
91 	}
92 
93 	blexit();
94 /*--------------------------------------------------------------*/
95 	blenter();
96 
97 	for (m = 1; m >= 0; m <<= 1) {
98 		j = ~m;
99 		k = j + 1;
100 		l = abs(k);
101 		if (l != m)
102 			local_flag = FAILED;
103 	}
104 
105 	blexit();
106 /*--------------------------------------------------------------*/
107 /* Clean up any files created by test before call to anyfail.	*/
108 
109 	tst_exit();
110 }
111 
112 /*--------------------------------------------------------------*/
113 
114 /*****  LTP Port	*****/
setup(void)115 static void setup(void)
116 {
117 	temp = stderr;
118 }
119 
blenter(void)120 static int blenter(void)
121 {
122 	local_flag = PASSED;
123 	return (0);
124 }
125 
blexit(void)126 static int blexit(void)
127 {
128 	(local_flag == PASSED) ? tst_resm(TPASS,
129 					  "Test passed") : tst_resm(TFAIL,
130 								    "Test failed");
131 	return (0);
132 }
133 
134 /******			*****/
135