np/numparser2.h

Mon, 16 Feb 2004 18:04:44 +0100

author
tuomov
date
Mon, 16 Feb 2004 18:04:44 +0100
changeset 60
a4033700e35c
child 62
aae5facf9fc5
permissions
-rw-r--r--

trunk: changeset 1313
Moved Ion object system and other generic code from Ion to libtu.

60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
1 /*
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
2 * libtu/numparser2.h
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
3 *
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2002.
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
5 *
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
6 * You may distribute and modify this library under the terms of either
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
8 */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
9
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
10 #define MAX_MANTISSA 10 /* should be enough for our needs */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
11 #define ULONG_SIZE (sizeof(ulong)*8)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
12
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
13 enum{
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
14 NPNUM_INT,
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
15 NPNUM_FLOAT
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
16 };
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
17
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
18 #ifdef NP_SIMPLE_IMPL
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
19
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
20 typedef struct _NPNum{
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
21 int type;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
22 int base;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
23 bool negative;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
24 double fval;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
25 ulong ival;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
26 } NPNum;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
27
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
28 #define NUM_INIT {0, 0, 0, 0.0, 0}
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
29
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
30 static int npnum_mulbase_add(NPNum *num, long base, long v)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
31 {
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
32 double iold=num->ival;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
33
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
34 num->fval=num->fval*base+(double)v;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
35
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
36 num->ival*=base;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
37
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
38 if(num->ival<iold)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
39 num->type=NPNUM_FLOAT;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
40
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
41 num->ival+=v;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
42
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
43 return 0;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
44 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
45
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
46 #else /* NP_SIMPLE_IMPL */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
47
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
48 typedef struct _NPNum{
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
49 unsigned char nmantissa;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
50 int type;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
51 int base;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
52 bool negative;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
53 ulong mantissa[MAX_MANTISSA];
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
54 long exponent;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
55 } NPNum;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
56
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
57 #define NUM_INIT {0, 0, 0, 0, {0,}, 0}
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
58
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
59 #define ADD_EXP(NUM, X) (NUM)->exponent+=(X);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
61 #if defined(__GNUG__) && defined(i386) && !defined(NP_NO_I386_ASM)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
62 #define NP_I386_ASM
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
63 #endif
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
64
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
65 static int npnum_mulbase_add(NPNum *num, long base, long v)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
66 {
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
67 long i, j;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
68 ulong overflow;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
69 #ifndef NP_I386_ASM
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
70 ulong val;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
71 #endif
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
72
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
73 for(i=num->nmantissa;i>=0;i--){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
74 #ifdef NP_I386_ASM
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
75 __asm__("mul %4\n"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
76 : "=a" (num->mantissa[i]), "=d" (overflow)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
77 : "0" (num->mantissa[i]), "1" (0), "q" (base)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
78 : "eax", "edx");
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
79 #else
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
80 overflow=0;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
81 val=num->mantissa[i];
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
82
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
83 if(val<ULONG_MAX/base){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
84 val*=base;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
85 }else if(val){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
86 ulong tmp=val;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
87 ulong old=val;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
88 for(j=0; j<base; j++){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
89 val+=tmp;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
90 if(val<=old)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
91 overflow++;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
92 old=val;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
93 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
94 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
95 num->mantissa[i]=val;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
96 #endif
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
97 if(overflow){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
98 if(i==num->nmantissa){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
99 if(num->nmantissa==MAX_MANTISSA)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
100 return E_TOKZ_TOOBIG;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
101 num->nmantissa++;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
102 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
103 num->mantissa[i+1]+=overflow;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
104 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
105 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
106 num->mantissa[0]+=v;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
107
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
108 return 0;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
109 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
110
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
111 #undef NP_I386_ASM
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
112
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
113 #endif /* NP_SIMPLE_IMPL */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
114
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
115
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
116 /* */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
117
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
118
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
119 static bool is_end(int c)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
120 {
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
121 /* oops... EOF was missing */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
122 return (c==EOF || (c!='.' && ispunct(c)) || isspace(c) || iscntrl(c));
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
123 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
124
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
125
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
126 /* */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
127
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
128
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
129 static int parse_exponent(NPNum *num, Tokenizer *tokz, int c)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
130 {
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
131 long exp=0;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
132 bool neg=FALSE;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
133 int err=0;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
134
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
135 c=GETCH();
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
136
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
137 if(c=='-' || c=='+'){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
138 if(c=='-')
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
139 neg=TRUE;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
140 c=GETCH();
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
141 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
142
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
143 for(; 1; c=GETCH()){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
144 if(isdigit(c)){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
145 exp*=10;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
146 exp+=c-'0';
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
147 }else if(is_end(c)){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
148 UNGETCH(c);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
149 break;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
150 }else{
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
151 err=E_TOKZ_NUMFMT;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
152 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
153 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
154
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
155 if(neg)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
156 exp*=-1;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
157
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
158 #ifndef NP_SIMPLE_IMPL
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
159 ADD_EXP(num, exp);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
160 #else
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
161 num->fval*=pow(num->base, exp);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
162 #endif
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
163 return err;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
164 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
165
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
166
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
167 static int parse_number(NPNum *num, Tokenizer *tokz, int c)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
168 {
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
169 int base=10;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
170 int dm=1;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
171 int err=0;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
172 int tmp;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
173 #ifdef NP_SIMPLE_IMPL
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
174 double divisor=base;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
175 #endif
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
176
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
177 if(c=='-' || c=='+'){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
178 if(c=='-')
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
179 num->negative=TRUE;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
180 c=GETCH();
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
181 if(!isdigit(c))
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
182 err=E_TOKZ_NUMFMT;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
183 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
184
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
185 if(c=='0'){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
186 dm=0;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
187 c=GETCH();
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
188 if(c=='x' || c=='X'){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
189 base=16;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
190 c=GETCH();
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
191 }else if(c=='b' || c=='B'){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
192 base=2;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
193 c=GETCH();
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
194 }else if('0'<=c && c<='7'){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
195 base=8;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
196 }else{
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
197 dm=2;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
198 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
199 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
200
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
201 num->base=base;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
202
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
203 for(; 1; c=GETCH()){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
204 if((c=='e' || c=='E') && dm!=0){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
205 if(dm<2){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
206 err=E_TOKZ_NUMFMT;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
207 continue;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
208 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
209 tmp=parse_exponent(num, tokz, c);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
210 if(err==0)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
211 err=tmp;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
212 break;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
213 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
214
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
215 if(isxdigit(c)){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
216 if('0'<=c && c<='9')
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
217 c-='0';
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
218 else if(isupper(c))
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
219 c-='A'-10;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
220 else
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
221 c-='a'-10;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
222
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
223 if(c>=base)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
224 err=E_TOKZ_NUMFMT;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
225
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
226 #ifdef NP_SIMPLE_IMPL
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
227 if(dm==3){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
228 num->fval+=(double)c/divisor;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
229 divisor*=base;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
230 }else
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
231 #endif
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
232 {
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
233 tmp=npnum_mulbase_add(num, base, c);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
234 if(err==0)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
235 err=tmp;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
236 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
237
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
238 if(dm==1)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
239 dm=2;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
240 #ifndef NP_SIMPLE_IMPL
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
241 else if(dm==3)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
242 ADD_EXP(num, -1);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
243 #endif
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
244 continue;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
245 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
246
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
247 if(c=='.'){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
248 if(dm!=2){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
249 err=E_TOKZ_NUMFMT;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
250 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
251 dm=3;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
252 #ifdef NP_SIMPLE_IMPL
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
253 num->type=NPNUM_FLOAT;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
254 divisor=base;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
255 #endif
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
256 continue;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
257 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
258
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
259 if(is_end(c)){
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
260 UNGETCH(c);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
261 break;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
262 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
263
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
264 err=E_TOKZ_NUMFMT;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
265 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
266
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
267 #ifndef NP_SIMPLE_IMPL
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
268 num->type=(num->exponent==0 ? NPNUM_INT : NPNUM_FLOAT);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
269 #endif
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
270
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
271 return err;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
272 }

mercurial