• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static int create_Result_file(void)
39 {
40 
41 	int i, nbVal, tabRI[20000];
42 	double tabR[20000], Inc, Val;
43 	char *F_name, *F_name1;
44 	int fp, fp1;
45 
46 	F_name = "frexp_out.ref";
47 	F_name1 = "frexp1_out.ref";
48 	nbVal = 20000;
49 
50 	Inc = exp(1);
51 
52 	for (i = 0; i < nbVal; i++) {
53 		Val = Inc * (i + 1);
54 		tabR[i] = frexp(Val, &(tabRI[i]));
55 	}
56 
57 	fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
58 	fp1 = open(F_name1, O_RDWR | O_CREAT | O_TRUNC, 0777);
59 	if (!fp || !fp1) {
60 		printf("error opening file");
61 		close(fp);
62 		close(fp1);
63 		return -1;
64 	} else {
65 		for (i = 0; i < nbVal; i++) {
66 			write(fp, &tabR[i], sizeof(double));
67 			write(fp1, &tabRI[i], sizeof(int));
68 		}
69 
70 		close(fp);
71 		close(fp1);
72 		return 0;
73 	}
74 }
75 
create_Data_file(void)76 static int create_Data_file(void)
77 {
78 	int i, nbVal;
79 	double tabD[20000], Inc;
80 	char *F_name;
81 	int fp;
82 
83 	F_name = "frexp_inp.ref";
84 	nbVal = 20000;
85 
86 	Inc = exp(1);
87 
88 	for (i = 0; i < nbVal; i++)
89 		tabD[i] = (Inc * i) + Inc;
90 
91 	fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
92 	if (!fp) {
93 		printf("error opening file");
94 		close(fp);
95 		return -1;
96 	} else {
97 		for (i = 0; i < nbVal; i++) {
98 			write(fp, &tabD[i], sizeof(double));
99 		}
100 		close(fp);
101 		return 0;
102 	}
103 }
104 
main(int argc,char * argv[])105 int main(int argc, char *argv[])
106 {
107 
108 	if (argc > 1) {
109 		switch (atoi(argv[1])) {
110 		case 1:
111 			if (create_Data_file() == 0)
112 				printf("Data file created\n");
113 			else
114 				printf("problem during %s data file creation\n",
115 				       argv[0]);
116 			break;
117 
118 		case 2:
119 			if (create_Result_file() == 0)
120 				printf("Result file created\n");
121 			else
122 				printf
123 				    ("problem during %s result file creation\n",
124 				     argv[0]);
125 			break;
126 		default:
127 			printf("Bad arglist code for: '%s'\n", argv[0]);
128 			return -1;
129 			break;
130 		}
131 	} else {
132 		if (create_Data_file() != 0)
133 			printf("problem during %s data file creation\n",
134 			       argv[0]);
135 		if (create_Result_file() != 0)
136 			printf("problem during %s result file creation\n",
137 			       argv[0]);
138 	}
139 
140 	return (0);
141 
142 }
143