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