blob: 3bd44efabb22d2c9a63303a960c9d0b3c9b28455 [file] [log] [blame]
robbiewa76e4752003-01-03 22:48:42 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiewa76e4752003-01-03 22:48:42 +000018 */
19
robbiew19e6a8b2003-01-03 21:42:16 +000020/* 01/02/2003 Port to LTP avenkat@us.ibm.com */
21/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
22
23/*
robbiew19e6a8b2003-01-03 21:42:16 +000024 * 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 */
robbiewda0cc972003-03-28 17:18:51 +000037#define _GNU_SOURCE 1
robbiew19e6a8b2003-01-03 21:42:16 +000038
Wanlong Gao354ebb42012-12-07 10:10:04 +080039#include <stdio.h> /* needed by testhead.h */
robbiew19e6a8b2003-01-03 21:42:16 +000040#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"
robbiew19e6a8b2003-01-03 21:42:16 +000050#define FAILED 0
51#define PASSED 1
52
53char *TCID = "abs01";
54int local_flag = PASSED;
55int block_number;
56int errno;
Wanlong Gao354ebb42012-12-07 10:10:04 +080057FILE *temp;
58int TST_TOTAL = 1;
robbiew19e6a8b2003-01-03 21:42:16 +000059
robbiew19e6a8b2003-01-03 21:42:16 +000060void setup();
61int blenter();
62int blexit();
63
64/********************************/
65
66/*--------------------------------------------------------------*/
Wanlong Gao354ebb42012-12-07 10:10:04 +080067int main(argc, argv)
68int argc;
69char *argv[];
robbiew19e6a8b2003-01-03 21:42:16 +000070{
robbiewed8de1d2003-03-27 23:07:01 +000071 register long long i;
Wanlong Gao354ebb42012-12-07 10:10:04 +080072 register int j, k, l, m;
robbiew19e6a8b2003-01-03 21:42:16 +000073
Wanlong Gao354ebb42012-12-07 10:10:04 +080074 setup(); /* temp file is now open */
robbiew19e6a8b2003-01-03 21:42:16 +000075/*--------------------------------------------------------------*/
76 blenter();
77
robbiew740674e2003-04-01 21:17:08 +000078 i = llabs(MININT) + (long long)MININT;
Garrett Cooper2c282152010-12-16 00:55:50 -080079
robbiew740674e2003-04-01 21:17:08 +000080 if (i != 0) {
robbiew19e6a8b2003-01-03 21:42:16 +000081 fprintf(temp, "abs of minimum integer failed.");
82 local_flag = FAILED;
83 }
84
robbiew19e6a8b2003-01-03 21:42:16 +000085 blexit();
86/*--------------------------------------------------------------*/
87 blenter();
88
robbiewed8de1d2003-03-27 23:07:01 +000089 i = llabs(0);
robbiew19e6a8b2003-01-03 21:42:16 +000090 if (i != 0) {
robbiewda0cc972003-03-28 17:18:51 +000091 fprintf(temp, "abs(0) failed, returned %lld\n", i);
robbiew19e6a8b2003-01-03 21:42:16 +000092 local_flag = FAILED;
93 }
94
95 blexit();
96/*--------------------------------------------------------------*/
97 blenter();
98
Wanlong Gao354ebb42012-12-07 10:10:04 +080099 for (m = 1; m >= 0; m <<= 1) {
robbiewed8de1d2003-03-27 23:07:01 +0000100 j = ~m;
robbiew19e6a8b2003-01-03 21:42:16 +0000101 k = j + 1;
102 l = abs(k);
robbiewed8de1d2003-03-27 23:07:01 +0000103 if (l != m)
robbiew19e6a8b2003-01-03 21:42:16 +0000104 local_flag = FAILED;
105 }
106
107 blexit();
108/*--------------------------------------------------------------*/
109/* Clean up any files created by test before call to anyfail. */
110
Garrett Cooper4b20b1d2010-12-18 01:06:11 -0800111 tst_exit();
robbiew19e6a8b2003-01-03 21:42:16 +0000112}
Wanlong Gao354ebb42012-12-07 10:10:04 +0800113
robbiew19e6a8b2003-01-03 21:42:16 +0000114/*--------------------------------------------------------------*/
115
116/***** LTP Port *****/
117void setup()
118{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800119 temp = stderr;
robbiew19e6a8b2003-01-03 21:42:16 +0000120}
121
robbiew19e6a8b2003-01-03 21:42:16 +0000122int blenter()
123{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800124 local_flag = PASSED;
125 return (0);
robbiew19e6a8b2003-01-03 21:42:16 +0000126}
127
robbiew19e6a8b2003-01-03 21:42:16 +0000128int blexit()
129{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800130 (local_flag == PASSED) ? tst_resm(TPASS,
131 "Test passed") : tst_resm(TFAIL,
132 "Test failed");
133 return (0);
robbiew19e6a8b2003-01-03 21:42:16 +0000134}
135
Chris Dearmanec6edca2012-10-17 19:54:01 -0700136/****** *****/