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