L
luser- -droog
A productive 3-day weekend! Counting everything in systemdict,
it's got 181 operators.
http://code.google.com/p/xpost/downloads/list
The one I'd been dreading turned out pretty well, I think.
After I wrote it, I just kind of stared at it for a while.
But when I dared to try it, it worked!
/*
(15, 2)
(7, 2) 1
(3, 2) 1 1
(1, 2) 1 1 1
1 1 1 1
*/
int conv_rad (int num, int rad, char *s, int n) {
char *vec =
"0123456789"
"ABCDEFGHIJKLM"
"NOPQRSTUVWXYZ";
int off;
if (n == 0) return 0;
if (num < rad) {
*s = vec[num];
return 1;
}
off = conv_rad(num/rad, rad, s, n);
if ((off == n) || (off == -1)) return -1;
s[off] = vec[num%rad];
return off+1;
}
/* num radix string cvrs substring
convert to string with radix
*/
void Ocvrs (Object *o) {
int rad, n;
char *s;
if (type(o[0]) == realtype) o[0] = makeinteger(o[0].r);
if (!typearg3(integer,integer,string)) error(typecheck, OP_cvrs);
rad = o[1].i;
if ( (rad < 2) || (rad > 36)) error(rangecheck, OP_cvrs);
s = (char *)VM(o[2].s);
n = o[2].n;
n = conv_rad(o[0].i, rad, s, n);
if (n == -1) error(rangecheck, OP_cvrs);
o[0] = substring(o[2], 0, n);
}
it's got 181 operators.
http://code.google.com/p/xpost/downloads/list
The one I'd been dreading turned out pretty well, I think.
After I wrote it, I just kind of stared at it for a while.
But when I dared to try it, it worked!
/*
(15, 2)
(7, 2) 1
(3, 2) 1 1
(1, 2) 1 1 1
1 1 1 1
*/
int conv_rad (int num, int rad, char *s, int n) {
char *vec =
"0123456789"
"ABCDEFGHIJKLM"
"NOPQRSTUVWXYZ";
int off;
if (n == 0) return 0;
if (num < rad) {
*s = vec[num];
return 1;
}
off = conv_rad(num/rad, rad, s, n);
if ((off == n) || (off == -1)) return -1;
s[off] = vec[num%rad];
return off+1;
}
/* num radix string cvrs substring
convert to string with radix
*/
void Ocvrs (Object *o) {
int rad, n;
char *s;
if (type(o[0]) == realtype) o[0] = makeinteger(o[0].r);
if (!typearg3(integer,integer,string)) error(typecheck, OP_cvrs);
rad = o[1].i;
if ( (rad < 2) || (rad > 36)) error(rangecheck, OP_cvrs);
s = (char *)VM(o[2].s);
n = o[2].n;
n = conv_rad(o[0].i, rad, s, n);
if (n == -1) error(rangecheck, OP_cvrs);
o[0] = substring(o[2], 0, n);
}