1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Copyright (C) Bull S.A. 2001
3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines  Corp., 2001
4f08c3bdfSopenharmony_ci *
5f08c3bdfSopenharmony_ci *   This program is free software;  you can redistribute it and/or modify
6f08c3bdfSopenharmony_ci *   it under the terms of the GNU General Public License as published by
7f08c3bdfSopenharmony_ci *   the Free Software Foundation; either version 2 of the License, or
8f08c3bdfSopenharmony_ci *   (at your option) any later version.
9f08c3bdfSopenharmony_ci *
10f08c3bdfSopenharmony_ci *   This program is distributed in the hope that it will be useful,
11f08c3bdfSopenharmony_ci *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12f08c3bdfSopenharmony_ci *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13f08c3bdfSopenharmony_ci *   the GNU General Public License for more details.
14f08c3bdfSopenharmony_ci *
15f08c3bdfSopenharmony_ci *   You should have received a copy of the GNU General Public License
16f08c3bdfSopenharmony_ci *   along with this program;  if not, write to the Free Software
17f08c3bdfSopenharmony_ci *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18f08c3bdfSopenharmony_ci */
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_ci/******************************************************************************/
21f08c3bdfSopenharmony_ci/*                                                                            */
22f08c3bdfSopenharmony_ci/* Dec-03-2001  Created: Jacky Malcles & Jean Noel Cordenner                  */
23f08c3bdfSopenharmony_ci/*              These tests are adapted from AIX float PVT tests.             */
24f08c3bdfSopenharmony_ci/*                                                                            */
25f08c3bdfSopenharmony_ci/******************************************************************************/
26f08c3bdfSopenharmony_ci#include <float.h>
27f08c3bdfSopenharmony_ci#include <stdio.h>
28f08c3bdfSopenharmony_ci#include <stdlib.h>
29f08c3bdfSopenharmony_ci#include <string.h>
30f08c3bdfSopenharmony_ci#include <errno.h>
31f08c3bdfSopenharmony_ci#include <limits.h>
32f08c3bdfSopenharmony_ci#include <unistd.h>
33f08c3bdfSopenharmony_ci#include <fcntl.h>
34f08c3bdfSopenharmony_ci#include <errno.h>
35f08c3bdfSopenharmony_ci#include <sys/signal.h>
36f08c3bdfSopenharmony_ci#include <math.h>
37f08c3bdfSopenharmony_ci
38f08c3bdfSopenharmony_ci/* **************************************
39f08c3bdfSopenharmony_ci *   create result file
40f08c3bdfSopenharmony_ci *
41f08c3bdfSopenharmony_ci *  the result is divided into 2 files
42f08c3bdfSopenharmony_ci * 1 double frationnal part of the input result of modf
43f08c3bdfSopenharmony_ci * 1 double which is the integral part of the input: tabRI
44f08c3bdfSopenharmony_ci *
45f08c3bdfSopenharmony_ci */
46f08c3bdfSopenharmony_ciint create_Result_file(void)
47f08c3bdfSopenharmony_ci{
48f08c3bdfSopenharmony_ci	int i, nbVal;
49f08c3bdfSopenharmony_ci	double tabR[20000], Val, Val1;
50f08c3bdfSopenharmony_ci	char *F_name, *F_namei1, *F_namei;
51f08c3bdfSopenharmony_ci	int fp, fpi1, fpi;
52f08c3bdfSopenharmony_ci
53f08c3bdfSopenharmony_ci	F_name = "fmod_out.ref";
54f08c3bdfSopenharmony_ci	F_namei = "fmod_inp.ref";
55f08c3bdfSopenharmony_ci	F_namei1 = "1fmod_inp.ref";
56f08c3bdfSopenharmony_ci	nbVal = 20000;
57f08c3bdfSopenharmony_ci
58f08c3bdfSopenharmony_ci	fpi = open(F_namei, O_RDONLY, 0777);
59f08c3bdfSopenharmony_ci	fpi1 = open(F_namei1, O_RDONLY, 0777);
60f08c3bdfSopenharmony_ci	if (!fpi || !fpi1) {
61f08c3bdfSopenharmony_ci		printf("error opening file");
62f08c3bdfSopenharmony_ci		close(fpi);
63f08c3bdfSopenharmony_ci		close(fpi1);
64f08c3bdfSopenharmony_ci		return -1;
65f08c3bdfSopenharmony_ci	} else {
66f08c3bdfSopenharmony_ci		for (i = 0; i < nbVal; i++) {
67f08c3bdfSopenharmony_ci			read(fpi, &Val, sizeof(double));
68f08c3bdfSopenharmony_ci			read(fpi1, &Val1, sizeof(double));
69f08c3bdfSopenharmony_ci
70f08c3bdfSopenharmony_ci			tabR[i] = fmod(Val, Val1);
71f08c3bdfSopenharmony_ci		}
72f08c3bdfSopenharmony_ci		close(fpi);
73f08c3bdfSopenharmony_ci		close(fpi1);
74f08c3bdfSopenharmony_ci
75f08c3bdfSopenharmony_ci		fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
76f08c3bdfSopenharmony_ci		if (!fp) {
77f08c3bdfSopenharmony_ci			printf("error opening file");
78f08c3bdfSopenharmony_ci			close(fp);
79f08c3bdfSopenharmony_ci			return -1;
80f08c3bdfSopenharmony_ci		} else {
81f08c3bdfSopenharmony_ci			for (i = 0; i < nbVal; i++) {
82f08c3bdfSopenharmony_ci				write(fp, &tabR[i], sizeof(double));
83f08c3bdfSopenharmony_ci			}
84f08c3bdfSopenharmony_ci
85f08c3bdfSopenharmony_ci			close(fp);
86f08c3bdfSopenharmony_ci			return 0;
87f08c3bdfSopenharmony_ci		}
88f08c3bdfSopenharmony_ci	}
89f08c3bdfSopenharmony_ci}
90f08c3bdfSopenharmony_ci
91f08c3bdfSopenharmony_ciint create_Data_file(void)
92f08c3bdfSopenharmony_ci{
93f08c3bdfSopenharmony_ci	int i, nbVal;
94f08c3bdfSopenharmony_ci	double tabD[20000], tabD1[20000], Inc;
95f08c3bdfSopenharmony_ci	char *F_name, *F_name1;
96f08c3bdfSopenharmony_ci	int fp, fp1;
97f08c3bdfSopenharmony_ci
98f08c3bdfSopenharmony_ci	F_name = "fmod_inp.ref";
99f08c3bdfSopenharmony_ci	F_name1 = "1fmod_inp.ref";
100f08c3bdfSopenharmony_ci	nbVal = 20000;
101f08c3bdfSopenharmony_ci
102f08c3bdfSopenharmony_ci	Inc = exp(1) / 10;
103f08c3bdfSopenharmony_ci
104f08c3bdfSopenharmony_ci	for (i = 0; i < nbVal; i++) {
105f08c3bdfSopenharmony_ci		tabD[i] = log((Inc * i) + Inc);
106f08c3bdfSopenharmony_ci		tabD1[i] = log(nbVal - (Inc * i) + Inc);
107f08c3bdfSopenharmony_ci	}
108f08c3bdfSopenharmony_ci
109f08c3bdfSopenharmony_ci	fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
110f08c3bdfSopenharmony_ci	fp1 = open(F_name1, O_RDWR | O_CREAT | O_TRUNC, 0777);
111f08c3bdfSopenharmony_ci	if (!fp || !fp1) {
112f08c3bdfSopenharmony_ci		printf("error opening file");
113f08c3bdfSopenharmony_ci		close(fp);
114f08c3bdfSopenharmony_ci		close(fp1);
115f08c3bdfSopenharmony_ci		return -1;
116f08c3bdfSopenharmony_ci	} else {
117f08c3bdfSopenharmony_ci		for (i = 0; i < nbVal; i++) {
118f08c3bdfSopenharmony_ci			write(fp, &tabD[i], sizeof(double));
119f08c3bdfSopenharmony_ci			write(fp1, &tabD1[i], sizeof(double));
120f08c3bdfSopenharmony_ci		}
121f08c3bdfSopenharmony_ci		close(fp);
122f08c3bdfSopenharmony_ci		close(fp1);
123f08c3bdfSopenharmony_ci		return 0;
124f08c3bdfSopenharmony_ci	}
125f08c3bdfSopenharmony_ci}
126f08c3bdfSopenharmony_ci
127f08c3bdfSopenharmony_ciint main(int argc, char *argv[])
128f08c3bdfSopenharmony_ci{
129f08c3bdfSopenharmony_ci	if (argc > 1) {
130f08c3bdfSopenharmony_ci		switch (atoi(argv[1])) {
131f08c3bdfSopenharmony_ci		case 1:
132f08c3bdfSopenharmony_ci			if (create_Data_file() == 0)
133f08c3bdfSopenharmony_ci				printf("Data file created\n");
134f08c3bdfSopenharmony_ci			else
135f08c3bdfSopenharmony_ci				printf("problem during %s data file creation\n",
136f08c3bdfSopenharmony_ci				       argv[0]);
137f08c3bdfSopenharmony_ci			break;
138f08c3bdfSopenharmony_ci
139f08c3bdfSopenharmony_ci		case 2:
140f08c3bdfSopenharmony_ci			if (create_Result_file() == 0)
141f08c3bdfSopenharmony_ci				printf("Result file created\n");
142f08c3bdfSopenharmony_ci			else
143f08c3bdfSopenharmony_ci				printf
144f08c3bdfSopenharmony_ci				    ("problem during %s result file creation\n",
145f08c3bdfSopenharmony_ci				     argv[0]);
146f08c3bdfSopenharmony_ci			break;
147f08c3bdfSopenharmony_ci		default:
148f08c3bdfSopenharmony_ci			printf("Bad arglist code for: '%s'\n", argv[0]);
149f08c3bdfSopenharmony_ci			return -1;
150f08c3bdfSopenharmony_ci			break;
151f08c3bdfSopenharmony_ci		}
152f08c3bdfSopenharmony_ci	} else {
153f08c3bdfSopenharmony_ci		if (create_Data_file() != 0)
154f08c3bdfSopenharmony_ci			printf("problem during %s data file creation\n",
155f08c3bdfSopenharmony_ci			       argv[0]);
156f08c3bdfSopenharmony_ci		if (create_Result_file() != 0)
157f08c3bdfSopenharmony_ci			printf("problem during %s result file creation\n",
158f08c3bdfSopenharmony_ci			       argv[0]);
159f08c3bdfSopenharmony_ci	}
160f08c3bdfSopenharmony_ci
161f08c3bdfSopenharmony_ci	return 0;
162f08c3bdfSopenharmony_ci}
163