blob: 0f272e03e8d184d0d82a787e172a5e0edd693501 [file] [log] [blame]
robbiew4487a902003-01-03 22:50:19 +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
robbiew4487a902003-01-03 22:50:19 +000018 */
19
20/* 01/02/2003 Port to LTP avenkat@us.ibm.com */
21/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
22
robbiew4487a902003-01-03 22:50:19 +000023/*
24 * NAME
Garrett Cooper2c282152010-12-16 00:55:50 -080025 * scalb
robbiew4487a902003-01-03 22:50:19 +000026 *
27 * CALLS
28 * nextafter(3C)
29 *
30 * ALGORITHM
31 * Check results from the above functions against expected values.
32 *
33 * RESTRICTIONS
34 * Checks for basic functionality, nothing fancy
35 */
36
Garrett Cooper316297f2010-12-18 00:54:26 -080037#include <errno.h>
38#include <math.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include "test.h"
robbiew4487a902003-01-03 22:50:19 +000042
43#define FAILED 0
44#define PASSED 1
45
46char *TCID = "nextafter01";
47
48int local_flag = PASSED;
49int block_number;
50int errno;
51FILE *temp;
52int TST_TOTAL = 1;
robbiew4487a902003-01-03 22:50:19 +000053
54void setup();
Garrett Cooper316297f2010-12-18 00:54:26 -080055void blenter();
56void blexit();
robbiew4487a902003-01-03 22:50:19 +000057
58/*--------------------------------------------------------------*/
59int main()
60{
61 double answer;
Wanlong Gao354ebb42012-12-07 10:10:04 +080062 double check; /* tmp variable */
robbiew4487a902003-01-03 22:50:19 +000063
64 setup(); /* temp file is now open */
65/*--------------------------------------------------------------*/
Garrett Cooper316297f2010-12-18 00:54:26 -080066 blenter();
robbiew4487a902003-01-03 22:50:19 +000067
68 answer = nextafter(1.0, 1.1);
69 check = (answer + 1.0) / 2;
70 if ((check != answer) && ((float)check != 1.0)) {
71 fprintf(temp, "nextafter returned %e, expected answer or 1.0\n",
Wanlong Gao354ebb42012-12-07 10:10:04 +080072 answer);
robbiew4487a902003-01-03 22:50:19 +000073 local_flag = FAILED;
74 }
75
Wanlong Gao354ebb42012-12-07 10:10:04 +080076 blexit();
robbiew4487a902003-01-03 22:50:19 +000077/*--------------------------------------------------------------*/
Garrett Cooper316297f2010-12-18 00:54:26 -080078 blenter();
robbiew4487a902003-01-03 22:50:19 +000079
80 answer = nextafter(1.0, 0.9);
81 if ((check != answer) && (check != 1.0)) {
82 fprintf(temp, "nextafter returned %e, expected answer or 1.0\n",
Wanlong Gao354ebb42012-12-07 10:10:04 +080083 answer);
robbiew4487a902003-01-03 22:50:19 +000084 local_flag = FAILED;
85 }
86
Wanlong Gao354ebb42012-12-07 10:10:04 +080087 blexit();
robbiew4487a902003-01-03 22:50:19 +000088/*--------------------------------------------------------------*/
Garrett Cooper316297f2010-12-18 00:54:26 -080089 blenter();
robbiew4487a902003-01-03 22:50:19 +000090
91 answer = nextafter(1.0, 1.0);
92 if (answer != 1.0) {
93 fprintf(temp, "nextafter 3 returned %e, expected 1.0\n",
Wanlong Gao354ebb42012-12-07 10:10:04 +080094 answer);
robbiew4487a902003-01-03 22:50:19 +000095 local_flag = FAILED;
96 }
97
Wanlong Gao354ebb42012-12-07 10:10:04 +080098 blexit();
robbiew4487a902003-01-03 22:50:19 +000099/*--------------------------------------------------------------*/
100
Garrett Cooper316297f2010-12-18 00:54:26 -0800101 tst_exit();
robbiew4487a902003-01-03 22:50:19 +0000102}
Wanlong Gao354ebb42012-12-07 10:10:04 +0800103
robbiew4487a902003-01-03 22:50:19 +0000104/*--------------------------------------------------------------*/
105
106/***** ***** LTP Port *****/
107
108/* FUNCTIONS */
109
110void setup()
111{
Garrett Cooper316297f2010-12-18 00:54:26 -0800112 temp = stderr;
robbiew4487a902003-01-03 22:50:19 +0000113}
114
Garrett Cooper316297f2010-12-18 00:54:26 -0800115void blenter()
robbiew4487a902003-01-03 22:50:19 +0000116{
Garrett Cooper316297f2010-12-18 00:54:26 -0800117 local_flag = PASSED;
robbiew4487a902003-01-03 22:50:19 +0000118}
119
Garrett Cooper316297f2010-12-18 00:54:26 -0800120void blexit()
robbiew4487a902003-01-03 22:50:19 +0000121{
Garrett Cooper316297f2010-12-18 00:54:26 -0800122 if (local_flag == PASSED)
123 tst_resm(TPASS, "Test passed");
124 else
125 tst_resm(TFAIL, "Test failed");
robbiew4487a902003-01-03 22:50:19 +0000126}
127
Chris Dearmanec6edca2012-10-17 19:54:01 -0700128/***** ***** *****/