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 FILE *temp;
51 int TST_TOTAL = 1;
52
53 void setup();
54 void blenter();
55 void blexit();
56
57 /*--------------------------------------------------------------*/
main()58 int main()
59 {
60 double answer;
61 double check; /* tmp variable */
62
63 setup(); /* temp file is now open */
64 /*--------------------------------------------------------------*/
65 blenter();
66
67 answer = nextafter(1.0, 1.1);
68 check = (answer + 1.0) / 2;
69 if ((check != answer) && ((float)check != 1.0)) {
70 fprintf(temp, "nextafter returned %e, expected answer or 1.0\n",
71 answer);
72 local_flag = FAILED;
73 }
74
75 blexit();
76 /*--------------------------------------------------------------*/
77 blenter();
78
79 answer = nextafter(1.0, 0.9);
80 if ((check != answer) && (check != 1.0)) {
81 fprintf(temp, "nextafter returned %e, expected answer or 1.0\n",
82 answer);
83 local_flag = FAILED;
84 }
85
86 blexit();
87 /*--------------------------------------------------------------*/
88 blenter();
89
90 answer = nextafter(1.0, 1.0);
91 if (answer != 1.0) {
92 fprintf(temp, "nextafter 3 returned %e, expected 1.0\n",
93 answer);
94 local_flag = FAILED;
95 }
96
97 blexit();
98 /*--------------------------------------------------------------*/
99
100 tst_exit();
101 }
102
103 /*--------------------------------------------------------------*/
104
105 /***** ***** LTP Port *****/
106
107 /* FUNCTIONS */
108
setup()109 void setup()
110 {
111 temp = stderr;
112 }
113
blenter()114 void blenter()
115 {
116 local_flag = PASSED;
117 }
118
blexit()119 void blexit()
120 {
121 if (local_flag == PASSED)
122 tst_resm(TPASS, "Test passed");
123 else
124 tst_resm(TFAIL, "Test failed");
125 }
126
127 /***** ***** *****/
128