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 * scalb
26 *
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
37 #include <errno.h>
38 #include <math.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include "test.h"
42
43 #define FAILED 0
44 #define PASSED 1
45
46 char *TCID = "nextafter01";
47
48 int local_flag = PASSED;
49 int block_number;
50 int errno;
51 FILE *temp;
52 int TST_TOTAL = 1;
53
54 void setup();
55 void blenter();
56 void blexit();
57
58 /*--------------------------------------------------------------*/
main()59 int main()
60 {
61 double answer;
62 double check; /* tmp variable */
63
64 setup(); /* temp file is now open */
65 /*--------------------------------------------------------------*/
66 blenter();
67
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",
72 answer);
73 local_flag = FAILED;
74 }
75
76 blexit();
77 /*--------------------------------------------------------------*/
78 blenter();
79
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",
83 answer);
84 local_flag = FAILED;
85 }
86
87 blexit();
88 /*--------------------------------------------------------------*/
89 blenter();
90
91 answer = nextafter(1.0, 1.0);
92 if (answer != 1.0) {
93 fprintf(temp, "nextafter 3 returned %e, expected 1.0\n",
94 answer);
95 local_flag = FAILED;
96 }
97
98 blexit();
99 /*--------------------------------------------------------------*/
100
101 tst_exit();
102 }
103
104 /*--------------------------------------------------------------*/
105
106 /***** ***** LTP Port *****/
107
108 /* FUNCTIONS */
109
setup()110 void setup()
111 {
112 temp = stderr;
113 }
114
blenter()115 void blenter()
116 {
117 local_flag = PASSED;
118 }
119
blexit()120 void blexit()
121 {
122 if (local_flag == PASSED)
123 tst_resm(TPASS, "Test passed");
124 else
125 tst_resm(TFAIL, "Test failed");
126 }
127
128 /***** ***** *****/
129