1 /*
2  * Copyright (C) Bull S.A. 2001
3  * Copyright (c) International Business Machines  Corp., 2001
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 /******************************************************************************/
21 /*                                                                            */
22 /* Dec-03-2001  Created: Jacky Malcles & Jean Noel Cordenner                  */
23 /*              These tests are adapted from AIX float PVT tests.             */
24 /*                                                                            */
25 /******************************************************************************/
26 #include <float.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <errno.h>
31 #include <limits.h>
32 #include <unistd.h>
33 #include <fcntl.h>
34 #include <errno.h>
35 #include <sys/signal.h>
36 #include <math.h>
37 
create_Result_file(void)38 int create_Result_file(void)
39 {
40 	int i, nbVal;
41 	double tabR[20000], Val_X, Val_Y;
42 	char *F_name, *F_namei1, *F_namei;
43 	int fp, fpi1, fpi;
44 
45 	F_name = "pow_out.ref";
46 	F_namei = "pow_inp.ref";
47 	F_namei1 = "1pow_inp.ref";
48 	nbVal = 20000;
49 
50 	fpi = open(F_namei, O_RDONLY, 0777);
51 	fpi1 = open(F_namei1, O_RDONLY, 0777);
52 	if (!fpi || !fpi1) {
53 		printf("error opening file");
54 		close(fpi);
55 		close(fpi1);
56 		return -1;
57 	} else {
58 		for (i = 0; i < nbVal; i++) {
59 			read(fpi, &Val_X, sizeof(double));
60 			read(fpi1, &Val_Y, sizeof(double));
61 			tabR[i] = pow(Val_X, Val_Y);
62 		}
63 		close(fpi);
64 		close(fpi1);
65 
66 		fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
67 		if (!fp) {
68 			printf("error opening file");
69 			close(fp);
70 			return -1;
71 		} else {
72 			for (i = 0; i < nbVal; i++) {
73 				write(fp, &tabR[i], sizeof(double));
74 			}
75 
76 			close(fp);
77 			return 0;
78 		}
79 	}
80 }
81 
create_Data_file(void)82 int create_Data_file(void)
83 {
84 	int i, nbVal;
85 	double tabD[20000], tabD_pow[20000], Inc, Inc_pow;
86 	char *F_name, *F_name_pow;
87 	int fp, fp2;
88 
89 	F_name = "pow_inp.ref";
90 	F_name_pow = "1pow_inp.ref";
91 	nbVal = 20000;
92 
93 	Inc = exp(1);
94 	Inc_pow = exp(1) / 100;
95 
96 	for (i = 0; i < nbVal; i++) {
97 		tabD_pow[nbVal - (i + 1)] = Inc_pow * i + Inc_pow;
98 		tabD[i] = (Inc * i) + Inc;
99 	}
100 
101 	fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
102 	fp2 = open(F_name_pow, O_RDWR | O_CREAT | O_TRUNC, 0777);
103 	if (!fp || !fp2) {
104 		printf("error opening file");
105 		close(fp);
106 		close(fp2);
107 		return -1;
108 	} else {
109 		for (i = 0; i < nbVal; i++) {
110 			write(fp, &tabD[i], sizeof(double));
111 			write(fp2, &tabD_pow[i], sizeof(double));
112 		}
113 		close(fp);
114 		close(fp2);
115 		return 0;
116 	}
117 }
118 
main(int argc,char * argv[])119 int main(int argc, char *argv[])
120 {
121 	if (argc > 1) {
122 		switch (atoi(argv[1])) {
123 		case 1:
124 			if (create_Data_file() == 0)
125 				printf("Data file created\n");
126 			else
127 				printf("problem during %s data file creation\n",
128 				       argv[0]);
129 			break;
130 
131 		case 2:
132 			if (create_Result_file() == 0)
133 				printf("Result file created\n");
134 			else
135 				printf
136 				    ("problem during %s result file creation\n",
137 				     argv[0]);
138 			break;
139 		default:
140 			printf("Bad arglist code for: '%s'\n", argv[0]);
141 			return -1;
142 			break;
143 		}
144 	} else {
145 		if (create_Data_file() != 0)
146 			printf("problem during %s data file creation\n",
147 			       argv[0]);
148 		if (create_Result_file() != 0)
149 			printf("problem during %s result file creation\n",
150 			       argv[0]);
151 	}
152 
153 	return 0;
154 }
155