* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* integer to ascii conversion
* This code has been rearranged to produce optimized runtime code.
static char _digit
[] = "0123456789abcdefghijklmnopqrstuvwxyz";
static char _icv_buf
[MAXINTLENGTH
+1];
icvt(value
, ndigit
, sign
)
register long val
= value
;
register long rad
= radix
;
register char *b
= &_icv_buf
[MAXINTLENGTH
];
register char *d
= _digit
;
if (signit
&& (*sign
= (val
< 0))) /* signed conversion */
* It is necessary to do the first divide
* before the absolute value, for the case -2^31
* This is actually what is being done...
* tmp1 = (int)(val % rad);
*--b
= d
[(tmp1
* rad
) - val
];
else /* unsigned conversion */
{ /* ALL THIS IS TO SIMULATE UNSIGNED LONG MOD & DIV */
kludge
= _mask
- (rad
- 1);
* This is really what's being done...
* rem = (kludge % rad) + (val % rad);
* val = (kludge / rad) + (val / rad) + (rem / rad) + 1;
rem
= (kludge
- (tmp1
* rad
)) + (val
- (tmp2
* rad
));
*--b
= d
[rem
- (tmp1
* rad
)];
* This is really what's being done ...
*--b
= d
[val
- (tmp1
* rad
)];
*ndigit
= (&_icv_buf
[MAXINTLENGTH
] - b
);