numparser2.h

changeset 15
9f5760af87d9
parent 9
55e7f2ff6021
child 36
63cd573ffbcf
equal deleted inserted replaced
14:91f0c87b62a7 15:9f5760af87d9
17 17
18 typedef struct _NPNum{ 18 typedef struct _NPNum{
19 int type; 19 int type;
20 int base; 20 int base;
21 bool negative; 21 bool negative;
22 long double fval; 22 double fval;
23 ulong ival; 23 ulong ival;
24 } NPNum; 24 } NPNum;
25 25
26 #define NUM_INIT {0, 0, 0, 0.0, 0} 26 #define NUM_INIT {0, 0, 0, 0.0, 0}
27 27
28 static int npnum_mulbase_add(NPNum *num, long base, long v) 28 static int npnum_mulbase_add(NPNum *num, long base, long v)
29 { 29 {
30 long double iold=num->ival; 30 double iold=num->ival;
31 31
32 num->fval=num->fval*base+(long double)v; 32 num->fval=num->fval*base+(double)v;
33 33
34 num->ival*=base; 34 num->ival*=base;
35 35
36 if(num->ival<iold) 36 if(num->ival<iold)
37 num->type=NPNUM_FLOAT; 37 num->type=NPNUM_FLOAT;
167 int base=10; 167 int base=10;
168 int dm=1; 168 int dm=1;
169 int err=0; 169 int err=0;
170 int tmp; 170 int tmp;
171 #ifdef NP_SIMPLE_IMPL 171 #ifdef NP_SIMPLE_IMPL
172 long double divisor=base; 172 double divisor=base;
173 #endif 173 #endif
174 174
175 if(c=='-' || c=='+'){ 175 if(c=='-' || c=='+'){
176 if(c=='-') 176 if(c=='-')
177 num->negative=TRUE; 177 num->negative=TRUE;
221 if(c>=base) 221 if(c>=base)
222 err=E_TOKZ_NUMFMT; 222 err=E_TOKZ_NUMFMT;
223 223
224 #ifdef NP_SIMPLE_IMPL 224 #ifdef NP_SIMPLE_IMPL
225 if(dm==3){ 225 if(dm==3){
226 num->fval+=(long double)c/divisor; 226 num->fval+=(double)c/divisor;
227 divisor*=base; 227 divisor*=base;
228 }else 228 }else
229 #endif 229 #endif
230 { 230 {
231 tmp=npnum_mulbase_add(num, base, c); 231 tmp=npnum_mulbase_add(num, base, c);

mercurial