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