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