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
38 /* **************************************
39 * create result file
40 *
41 * the result is divided into 2 files
42 * 1 double frationnal part of the input result of modf
43 * 1 double which is the integral part of the input: tabRI
44 *
45 */
create_Result_file(void)46 static int create_Result_file(void)
47 {
48
49 int i, nbVal;
50 double tabR[20000], Inc, tabRI[20000];
51 char *F_name, *F_name1;
52 int fp, fp1;
53 double TestInputValue, TestChkSum;
54
55 F_name = "modf_out.ref";
56 F_name1 = "modf1_out.ref";
57 nbVal = 20000;
58
59 Inc = log(exp(1) / 10);
60
61 for (i = 0; i < nbVal; i++) {
62 TestInputValue = ((Inc * i) + Inc);
63 tabR[i] = modf(TestInputValue, &tabRI[i]);
64 // tabR[i] = modf( ((Inc*i) + Inc), &tabRI[i]);
65 if ((TestChkSum = tabR[i] + tabRI[i]) != TestInputValue) {
66 return -1;
67 }
68
69 }
70
71 fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
72 fp1 = open(F_name1, O_RDWR | O_CREAT | O_TRUNC, 0777);
73 if (!fp || !fp1) {
74 printf("error opening file");
75 close(fp);
76 close(fp1);
77 return -1;
78 } else {
79 for (i = 0; i < nbVal; i++) {
80 write(fp, &tabR[i], sizeof(double));
81 write(fp1, &tabRI[i], sizeof(double));
82 }
83
84 close(fp);
85 close(fp1);
86 return 0;
87 }
88 }
89
create_Data_file(void)90 static int create_Data_file(void)
91 {
92 int i, nbVal;
93 double tabD[20000], Inc;
94 char *F_name;
95 int fp;
96
97 F_name = "modf_inp.ref";
98 nbVal = 20000;
99
100 Inc = log(exp(1) / 10);
101
102 for (i = 0; i < nbVal; i++)
103 tabD[i] = (Inc * i) + Inc;
104
105 fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
106 if (!fp) {
107 printf("error opening file");
108 close(fp);
109 return -1;
110 } else {
111 for (i = 0; i < nbVal; i++) {
112 write(fp, &tabD[i], sizeof(double));
113 }
114 close(fp);
115 return 0;
116 }
117 }
118
main(int argc,char * argv[])119 int main(int argc, char *argv[])
120 {
121
122 if (argc > 1) {
123 switch (atoi(argv[1])) {
124 case 1:
125 if (create_Data_file() == 0)
126 printf("Data file created\n");
127 else
128 printf("problem during %s data file creation\n",
129 argv[0]);
130 break;
131
132 case 2:
133 if (create_Result_file() == 0)
134 printf("Result file created\n");
135 else
136 printf
137 ("problem during %s result file creation\n",
138 argv[0]);
139 break;
140 default:
141 printf("Bad arglist code for: '%s'\n", argv[0]);
142 return -1;
143 break;
144 }
145 } else {
146 if (create_Data_file() != 0)
147 printf("problem during %s data file creation\n",
148 argv[0]);
149 if (create_Result_file() != 0)
150 printf("problem during %s result file creation\n",
151 argv[0]);
152 }
153
154 return (0);
155
156 }
157