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