1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2002
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker */
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker /* 01/02/2003 Port to LTP [email protected] */
21*49cdfc7eSAndroid Build Coastguard Worker /* 06/30/2001 Port to Linux [email protected] */
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker /*
24*49cdfc7eSAndroid Build Coastguard Worker * NAME
25*49cdfc7eSAndroid Build Coastguard Worker * scalb
26*49cdfc7eSAndroid Build Coastguard Worker *
27*49cdfc7eSAndroid Build Coastguard Worker * CALLS
28*49cdfc7eSAndroid Build Coastguard Worker * nextafter(3C)
29*49cdfc7eSAndroid Build Coastguard Worker *
30*49cdfc7eSAndroid Build Coastguard Worker * ALGORITHM
31*49cdfc7eSAndroid Build Coastguard Worker * Check results from the above functions against expected values.
32*49cdfc7eSAndroid Build Coastguard Worker *
33*49cdfc7eSAndroid Build Coastguard Worker * RESTRICTIONS
34*49cdfc7eSAndroid Build Coastguard Worker * Checks for basic functionality, nothing fancy
35*49cdfc7eSAndroid Build Coastguard Worker */
36*49cdfc7eSAndroid Build Coastguard Worker
37*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
38*49cdfc7eSAndroid Build Coastguard Worker #include <math.h>
39*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
40*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
42*49cdfc7eSAndroid Build Coastguard Worker
43*49cdfc7eSAndroid Build Coastguard Worker #define FAILED 0
44*49cdfc7eSAndroid Build Coastguard Worker #define PASSED 1
45*49cdfc7eSAndroid Build Coastguard Worker
46*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "nextafter01";
47*49cdfc7eSAndroid Build Coastguard Worker
48*49cdfc7eSAndroid Build Coastguard Worker int local_flag = PASSED;
49*49cdfc7eSAndroid Build Coastguard Worker int block_number;
50*49cdfc7eSAndroid Build Coastguard Worker FILE *temp;
51*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
52*49cdfc7eSAndroid Build Coastguard Worker
53*49cdfc7eSAndroid Build Coastguard Worker void setup();
54*49cdfc7eSAndroid Build Coastguard Worker void blenter();
55*49cdfc7eSAndroid Build Coastguard Worker void blexit();
56*49cdfc7eSAndroid Build Coastguard Worker
57*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
main()58*49cdfc7eSAndroid Build Coastguard Worker int main()
59*49cdfc7eSAndroid Build Coastguard Worker {
60*49cdfc7eSAndroid Build Coastguard Worker double answer;
61*49cdfc7eSAndroid Build Coastguard Worker double check; /* tmp variable */
62*49cdfc7eSAndroid Build Coastguard Worker
63*49cdfc7eSAndroid Build Coastguard Worker setup(); /* temp file is now open */
64*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
65*49cdfc7eSAndroid Build Coastguard Worker blenter();
66*49cdfc7eSAndroid Build Coastguard Worker
67*49cdfc7eSAndroid Build Coastguard Worker answer = nextafter(1.0, 1.1);
68*49cdfc7eSAndroid Build Coastguard Worker check = (answer + 1.0) / 2;
69*49cdfc7eSAndroid Build Coastguard Worker if ((check != answer) && ((float)check != 1.0)) {
70*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "nextafter returned %e, expected answer or 1.0\n",
71*49cdfc7eSAndroid Build Coastguard Worker answer);
72*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
73*49cdfc7eSAndroid Build Coastguard Worker }
74*49cdfc7eSAndroid Build Coastguard Worker
75*49cdfc7eSAndroid Build Coastguard Worker blexit();
76*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
77*49cdfc7eSAndroid Build Coastguard Worker blenter();
78*49cdfc7eSAndroid Build Coastguard Worker
79*49cdfc7eSAndroid Build Coastguard Worker answer = nextafter(1.0, 0.9);
80*49cdfc7eSAndroid Build Coastguard Worker if ((check != answer) && (check != 1.0)) {
81*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "nextafter returned %e, expected answer or 1.0\n",
82*49cdfc7eSAndroid Build Coastguard Worker answer);
83*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
84*49cdfc7eSAndroid Build Coastguard Worker }
85*49cdfc7eSAndroid Build Coastguard Worker
86*49cdfc7eSAndroid Build Coastguard Worker blexit();
87*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
88*49cdfc7eSAndroid Build Coastguard Worker blenter();
89*49cdfc7eSAndroid Build Coastguard Worker
90*49cdfc7eSAndroid Build Coastguard Worker answer = nextafter(1.0, 1.0);
91*49cdfc7eSAndroid Build Coastguard Worker if (answer != 1.0) {
92*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "nextafter 3 returned %e, expected 1.0\n",
93*49cdfc7eSAndroid Build Coastguard Worker answer);
94*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
95*49cdfc7eSAndroid Build Coastguard Worker }
96*49cdfc7eSAndroid Build Coastguard Worker
97*49cdfc7eSAndroid Build Coastguard Worker blexit();
98*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
99*49cdfc7eSAndroid Build Coastguard Worker
100*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
101*49cdfc7eSAndroid Build Coastguard Worker }
102*49cdfc7eSAndroid Build Coastguard Worker
103*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
104*49cdfc7eSAndroid Build Coastguard Worker
105*49cdfc7eSAndroid Build Coastguard Worker /***** ***** LTP Port *****/
106*49cdfc7eSAndroid Build Coastguard Worker
107*49cdfc7eSAndroid Build Coastguard Worker /* FUNCTIONS */
108*49cdfc7eSAndroid Build Coastguard Worker
setup()109*49cdfc7eSAndroid Build Coastguard Worker void setup()
110*49cdfc7eSAndroid Build Coastguard Worker {
111*49cdfc7eSAndroid Build Coastguard Worker temp = stderr;
112*49cdfc7eSAndroid Build Coastguard Worker }
113*49cdfc7eSAndroid Build Coastguard Worker
blenter()114*49cdfc7eSAndroid Build Coastguard Worker void blenter()
115*49cdfc7eSAndroid Build Coastguard Worker {
116*49cdfc7eSAndroid Build Coastguard Worker local_flag = PASSED;
117*49cdfc7eSAndroid Build Coastguard Worker }
118*49cdfc7eSAndroid Build Coastguard Worker
blexit()119*49cdfc7eSAndroid Build Coastguard Worker void blexit()
120*49cdfc7eSAndroid Build Coastguard Worker {
121*49cdfc7eSAndroid Build Coastguard Worker if (local_flag == PASSED)
122*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "Test passed");
123*49cdfc7eSAndroid Build Coastguard Worker else
124*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "Test failed");
125*49cdfc7eSAndroid Build Coastguard Worker }
126*49cdfc7eSAndroid Build Coastguard Worker
127*49cdfc7eSAndroid Build Coastguard Worker /***** ***** *****/
128