pelib
2.0.0
|
00001 /* 00002 * float.c 00003 * 00004 * Created on: 20 Feb 2012 00005 * Copyright 2012 Nicolas Melot 00006 * 00007 * This file is part of pelib. 00008 * 00009 * pelib is free software: you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation, either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * pelib is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with pelib. If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 */ 00023 00024 #include <stdlib.h> 00025 #include <math.h> 00026 00027 #include <pelib/float.h> 00028 00029 int 00030 pelib_copy(float)(float s1, float * s2) 00031 { 00032 *s2 = s1; 00033 00034 return 1; 00035 } 00036 00037 int 00038 pelib_init(float)(float *val) 00039 { 00040 *val = 0; 00041 00042 return 1; 00043 } 00044 00045 int 00046 pelib_compare(float)(float a, float b) 00047 { 00048 return a - b; 00049 } 00050 00051 char* 00052 pelib_string(float)(float a) 00053 { 00054 size_t size; 00055 char* str; 00056 00057 if(a > 0) 00058 { 00059 size = (float)log10(a); 00060 } 00061 else 00062 { 00063 size = 1; 00064 } 00065 str = malloc(sizeof(char) * (size + 2)); 00066 sprintf(str, "%f", a); 00067 00068 return str; 00069 } 00070 00071 char* 00072 pelib_string_detail(float)(float a, int level) 00073 { 00074 return pelib_string(float)(a); 00075 } 00076 00077 size_t 00078 pelib_fread(float)(float* buffer, FILE* stream) 00079 { 00080 // TODO: adapt for flat number parsing 00081 /* 00082 size_t total; 00083 int num; 00084 int read, has_more; 00085 00086 read = 0; 00087 has_more = 1; 00088 num = 0; 00089 total = 0; 00090 00091 while (read != ' ') 00092 { 00093 if ((has_more = fread(&read, sizeof(char), 1, stream)) == 0 || read == ' ') 00094 { 00095 break; 00096 } 00097 00098 total += has_more; 00099 num = num * 10 + read - '0'; 00100 } 00101 00102 *buffer = num; 00103 return total; 00104 */ 00105 fprintf(stderr, "[%s:%s:%d][ERROR] Not implemented. Aborting.\n", __FILE__, __FUNCTION__, __LINE__); 00106 return 0; 00107 } 00108 00109 // Now include the generic array implementation 00110 #define ARRAY_T float 00111 #include "pelib/array.c" 00112 00113 // Now include the generic fifo implementation 00114 #define CFIFO_T float 00115 #include "pelib/fifo.c" 00116 00117 // Now include the generic fifo implementation 00118 #define CFIFO_ARRAY_T float 00119 #include "pelib/fifo_array.c"