1 2 /* 3 * variable typedef's and error messages 4 * Copyright (c) 2002-2006 by Mattias Hultgren <mattias_hultgren@tele2.se> 5 * 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; version 2 of the License. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public 17 * License along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 21 /* 22 News 23 ---- 24 25 v9 2006-07-27 2006-10-05 26 -- 27 28 Extracted keyfile_io to it's own file 29 Removed all Throw_... functions 30 Added function uint64_to_char 31 32 v8 2006-06-01 33 -- 34 35 Implemented keyfile_io::operator= 36 Rewrote keyfile_io::write to use fopen instead of std::ofstream 37 38 v7 2006-02-25 39 -- 40 41 keyfile_io now supports lines with upto 5000 bytes (up from 500) 42 43 v6 2005-09-25 - 2005-11-06 44 -- 45 46 Added support for the escape sequence \" 47 Moved ump_float from math2.h into this file 48 Renamed error_lang -> translation 49 Renamed ump_float -> floatx (x symbolice that the precision is choosed at compile time) 50 51 v1.1.4 2005-07-30 52 ------ 53 54 Added an implementation of trunc using floor optional by -DDONT_HAVE_TRUNC 55 56 v1.1.3 2005-01-10 57 ------ 58 59 added more standard functions for translatable error message 60 added THROW_MACRO_FIX 61 62 v1.1.2 2004-10-17 - 2004-12-23 63 ------ 64 65 added int64_max, int64_min, uin64_max, uint64_min 66 small fixes 67 added more standard functions for translatable error message 68 fixed some compiler warnings 69 70 v1.1.1 2004-07-14 - 2004-09-01 71 ------ 72 73 added more standard functions for translatable error message 74 removed the Thrower field in error_obj 75 added support to replace escape sequences in keyfile_io 76 known escape sequences are \\ \n \r \t 77 added keyfile_io::write 78 79 v1.1.0 2004-06-30 - 2004-07-03 80 ------ 81 82 merged keyfile_io.h and vartypes.h 83 added some standard functions to ease up the work with translated error message 84 85 */ 86 87 #ifndef VARTYPES_H_ 88 #define VARTYPES_H_ 89 90 #define VARTYPES_H_VERSION "v9" 91 #define VARTYPES_H_DATE "2002-12 - 2006-08" 92 93 #include <math.h> 94 95 96 typedef unsigned char uint8; 97 typedef signed char int8; 98 const uint8 uint8_max = 0xff; 99 const uint8 uint8_min = 0x00; 100 const int8 int8_max = 0x7f; 101 const int8 int8_min = 0x80; 102 103 typedef unsigned short uint16; 104 typedef signed short int16; 105 const uint16 uint16_max = 0xffff; 106 const uint16 uint16_min = 0x0000; 107 const int16 int16_max = 0x7fff; 108 const int16 int16_min = 0x8000; 109 110 typedef unsigned int uint32; 111 typedef signed int int32; 112 const uint32 uint32_max = 0xffffffff; 113 const uint32 uint32_min = 0x00000000; 114 const int32 int32_max = 0x7fffffff; 115 const int32 int32_min = 0x80000000; 116 117 typedef unsigned long long int uint64; 118 typedef signed long long int int64; 119 const uint64 uint64_max = uint64(0) - 1; 120 const uint64 uint64_min = 0; 121 const int64 int64_max = int64(uint64_max >> 1); 122 const int64 int64_min = int64_max + 1; 123 124 125 // str must be big enough, and if val doesn't contain enough 126 // digits it will be zero padded from the left 127 void uint64_to_char( uint64 val, char *str, uint32 min_digits=0 ); 128 129 130 #ifdef DONT_HAVE_TRUNC 131 double trunc(double value); 132 #endif 133 #ifdef DONT_HAVE_LOG2 134 double log2(double value); 135 #endif 136 137 138 #ifdef USE_FLOAT 139 typedef float floatx; 140 sinx(floatx val)141 inline floatx sinx(floatx val) { return sinf(val); } cosx(floatx val)142 inline floatx cosx(floatx val) { return cosf(val); } tanx(floatx val)143 inline floatx tanx(floatx val) { return tanf(val); } asinx(floatx val)144 inline floatx asinx(floatx val) { return asinf(val); } acosx(floatx val)145 inline floatx acosx(floatx val) { return acosf(val); } atanx(floatx val)146 inline floatx atanx(floatx val) { return atanf(val); } sinhx(floatx val)147 inline floatx sinhx(floatx val) { return sinhf(val); } coshx(floatx val)148 inline floatx coshx(floatx val) { return coshf(val); } tanhx(floatx val)149 inline floatx tanhx(floatx val) { return tanhf(val); } asinhx(floatx val)150 inline floatx asinhx(floatx val) { return asinhf(val); } acoshx(floatx val)151 inline floatx acoshx(floatx val) { return acoshf(val); } atanhx(floatx val)152 inline floatx atanhx(floatx val) { return atanhf(val); } atan2x(floatx v1,floatx v2)153 inline floatx atan2x(floatx v1,floatx v2) { return atan2f(v1,v2); } hypotx(floatx v1,floatx v2)154 inline floatx hypotx(floatx v1,floatx v2) { return hypotf(v1,v2); } truncx(floatx val)155 inline floatx truncx(floatx val) { return truncf(val); } fabsx(floatx val)156 inline floatx fabsx(floatx val) { return fabsf(val); } logx(floatx val)157 inline floatx logx(floatx val) { return logf(val); } log2x(floatx val)158 inline floatx log2x(floatx val) { return log2f(val); } log10x(floatx val)159 inline floatx log10x(floatx val) { return log10f(val); } expx(floatx val)160 inline floatx expx(floatx val) { return expf(val); } sqrtx(floatx val)161 inline floatx sqrtx(floatx val) { return sqrtf(val); } powx(floatx v1,floatx v2)162 inline floatx powx(floatx v1,floatx v2) { return powf(v1,v2); } 163 #endif 164 #ifdef USE_DOUBLE 165 typedef double floatx; 166 sinx(floatx val)167 inline floatx sinx(floatx val) { return sin(val); } cosx(floatx val)168 inline floatx cosx(floatx val) { return cos(val); } tanx(floatx val)169 inline floatx tanx(floatx val) { return tan(val); } asinx(floatx val)170 inline floatx asinx(floatx val) { return asin(val); } acosx(floatx val)171 inline floatx acosx(floatx val) { return acos(val); } atanx(floatx val)172 inline floatx atanx(floatx val) { return atan(val); } sinhx(floatx val)173 inline floatx sinhx(floatx val) { return sinh(val); } coshx(floatx val)174 inline floatx coshx(floatx val) { return cosh(val); } tanhx(floatx val)175 inline floatx tanhx(floatx val) { return tanh(val); } asinhx(floatx val)176 inline floatx asinhx(floatx val) { return asinh(val); } acoshx(floatx val)177 inline floatx acoshx(floatx val) { return acosh(val); } atanhx(floatx val)178 inline floatx atanhx(floatx val) { return atanh(val); } atan2x(floatx v1,floatx v2)179 inline floatx atan2x(floatx v1,floatx v2) { return atan2(v1,v2); } hypotx(floatx v1,floatx v2)180 inline floatx hypotx(floatx v1,floatx v2) { return hypot(v1,v2); } truncx(floatx val)181 inline floatx truncx(floatx val) { return trunc(val); } fabsx(floatx val)182 inline floatx fabsx(floatx val) { return fabs(val); } logx(floatx val)183 inline floatx logx(floatx val) { return log(val); } log2x(floatx val)184 inline floatx log2x(floatx val) { return log2(val); } log10x(floatx val)185 inline floatx log10x(floatx val) { return log10(val); } expx(floatx val)186 inline floatx expx(floatx val) { return exp(val); } sqrtx(floatx val)187 inline floatx sqrtx(floatx val) { return sqrt(val); } powx(floatx v1,floatx v2)188 inline floatx powx(floatx v1,floatx v2) { return pow(v1,v2); } 189 #endif 190 #ifdef USE_LONG_DOUBLE 191 typedef long double floatx; 192 sinx(floatx val)193 inline floatx sinx(floatx val) { return sinl(val); } cosx(floatx val)194 inline floatx cosx(floatx val) { return cosl(val); } tanx(floatx val)195 inline floatx tanx(floatx val) { return tanl(val); } asinx(floatx val)196 inline floatx asinx(floatx val) { return asinl(val); } acosx(floatx val)197 inline floatx acosx(floatx val) { return acosl(val); } atanx(floatx val)198 inline floatx atanx(floatx val) { return atanl(val); } sinhx(floatx val)199 inline floatx sinhx(floatx val) { return sinhl(val); } coshx(floatx val)200 inline floatx coshx(floatx val) { return coshl(val); } tanhx(floatx val)201 inline floatx tanhx(floatx val) { return tanhl(val); } asinhx(floatx val)202 inline floatx asinhx(floatx val) { return asinhl(val); } acoshx(floatx val)203 inline floatx acoshx(floatx val) { return acoshl(val); } atanhx(floatx val)204 inline floatx atanhx(floatx val) { return atanhl(val); } atan2x(floatx v1,floatx v2)205 inline floatx atan2x(floatx v1,floatx v2) { return atan2l(v1,v2); } hypotx(floatx v1,floatx v2)206 inline floatx hypotx(floatx v1,floatx v2) { return hypotl(v1,v2); } truncx(floatx val)207 inline floatx truncx(floatx val) { return truncl(val); } fabsx(floatx val)208 inline floatx fabsx(floatx val) { return fabsl(val); } logx(floatx val)209 inline floatx logx(floatx val) { return logl(val); } log2x(floatx val)210 inline floatx log2x(floatx val) { return log2l(val); } log10x(floatx val)211 inline floatx log10x(floatx val) { return log10l(val); } expx(floatx val)212 inline floatx expx(floatx val) { return expl(val); } sqrtx(floatx val)213 inline floatx sqrtx(floatx val) { return sqrtl(val); } powx(floatx v1,floatx v2)214 inline floatx powx(floatx v1,floatx v2) { return powl(v1,v2); } 215 #endif 216 217 extern const floatx PI, E; 218 219 enum ErrorType { ErrorType_None, 220 ErrorType_Internal, 221 ErrorType_General, 222 ErrorType_Memory, 223 ErrorType_File_IO, 224 ErrorType_Domain, 225 ErrorType_Overflow, 226 ErrorType_Divide_by_zero, 227 ErrorType_Variable_not_found, 228 ErrorType_Name_isnt_unique, 229 ErrorType_UmpCode_General = 1000, 230 ErrorType_UmpCode_Domain, 231 ErrorType_UmpCode_Divide_by_zero }; 232 233 const uint32 ERROR_OBJ_MSG_LEN = 200; 234 struct error_obj 235 { 236 ErrorType type; 237 char msg[ERROR_OBJ_MSG_LEN]; 238 }; 239 240 241 242 #endif // VARTYPES_H_ 243