• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FILE *temp;
57 int TST_TOTAL = 1;
58 
59 static void setup(void);
60 static int blenter(void);
61 static int blexit(void);
62 
63 /********************************/
64 
65 /*--------------------------------------------------------------*/
main(int argc,char * argv[])66 int main(int argc, char *argv[])
67 {
68 	register long long i;
69 	register int j, k, l, m;
70 
71 	setup();		/* temp file is now open        */
72 /*--------------------------------------------------------------*/
73 	blenter();
74 
75 	i = llabs(MININT) + (long long)MININT;
76 
77 	if (i != 0) {
78 		fprintf(temp, "abs of minimum integer failed.");
79 		local_flag = FAILED;
80 	}
81 
82 	blexit();
83 /*--------------------------------------------------------------*/
84 	blenter();
85 
86 	i = llabs(0);
87 	if (i != 0) {
88 		fprintf(temp, "abs(0) failed, returned %lld\n", i);
89 		local_flag = FAILED;
90 	}
91 
92 	blexit();
93 /*--------------------------------------------------------------*/
94 	blenter();
95 
96 	for (m = 1; m >= 0; m <<= 1) {
97 		j = ~m;
98 		k = j + 1;
99 		l = abs(k);
100 		if (l != m)
101 			local_flag = FAILED;
102 	}
103 
104 	blexit();
105 /*--------------------------------------------------------------*/
106 /* Clean up any files created by test before call to anyfail.	*/
107 
108 	tst_exit();
109 }
110 
111 /*--------------------------------------------------------------*/
112 
113 /*****  LTP Port	*****/
setup(void)114 static void setup(void)
115 {
116 	temp = stderr;
117 }
118 
blenter(void)119 static int blenter(void)
120 {
121 	local_flag = PASSED;
122 	return (0);
123 }
124 
blexit(void)125 static int blexit(void)
126 {
127 	(local_flag == PASSED) ? tst_resm(TPASS,
128 					  "Test passed") : tst_resm(TFAIL,
129 								    "Test failed");
130 	return (0);
131 }
132 
133 /******			*****/
134