Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / mscan.cpp
blob2e3e6bc4b8388d605074a22d0e750ddf2f5b7df1
1 // bignum scanner
3 #include "stdafx.h"
4 #include "defs.h"
6 static unsigned int *addf(unsigned int *, int);
7 static unsigned int *mulf(unsigned int *, int);
9 unsigned int *
10 mscan(char *s)
12 int sign;
13 unsigned int *a, *b, *c;
15 sign = 1;
17 if (*s == '-') {
18 sign = -1;
19 s++;
22 a = mint(0);
24 while (*s) {
25 b = mulf(a, 10);
26 c = addf(b, *s - '0');
27 mfree(a);
28 mfree(b);
29 a = c;
30 s++;
33 if (!MZERO(a))
34 MSIGN(a) *= sign;
36 return a;
39 static unsigned int *
40 addf(unsigned int *a, int n)
42 unsigned int *b, *c;
43 b = mint(n);
44 c = madd(a, b);
45 mfree(b);
46 return c;
49 static unsigned int *
50 mulf(unsigned int *a, int n)
52 unsigned int *b, *c;
53 b = mint(n);
54 c = mmul(a, b);
55 mfree(b);
56 return c;