Trailing-Edge
-
PDP-10 Archives
-
decuslib10-05
-
43,50337/23/radix.sim
There is 1 other file named radix.sim in the archive. Click here to see a list.
! TEXT PROCEDURE RADIX returns a text containing
! the representation of input I in radix BASE.
! BASE may be negative but not -1 or zero.
! Resulting text will never contain blanks.
! If BASE = 16 then sequence 0123456789ABCDEF will be used,
! otherwise if BASE > 10 then
! the sequence 0123456789(10)(11)(12)... will be used.
!
! C.f. INTEGER PROCEDURE GETRADIX
!
! Author: Mats Ohlin, FOA 1, Fack, S-104 50 STOCKHOLM, SWEDEN.
! Date: 76-12-10
;
OPTIONS(/E/C/-Q/-A/-I/-D);
TEXT PROCEDURE radix(base,i); INTEGER base,i;
IF i = 0 THEN radix:- Copy("0") ELSE
IF base = 0 OR base = -1 OR base = 1 THEN radix:- Copy("*") ELSE
BEGIN INTEGER j,ndig,abase; BOOLEAN neg;
TEXT t; REF (dig) xdig;
CLASS dig(c); CHARACTER c;
BEGIN REF (dig) next;
next:- xdig; xdig:- THIS dig;
ndig:= ndig + 1;
END dig;
abase:= base*Sign(base);
IF base > 0 THEN neg:= i < 0;
IF neg THEN i:= -i;
WHILE i NE 0 DO
BEGIN j:= Mod(i,base);
IF j < 0 THEN
BEGIN j:= j - base; i:= i + base END;
! 48 = '0' 55 + 10 = 'A' ;
IF j <= 9 THEN NEW dig(Char(j+48)) ELSE
IF abase = 16 THEN NEW dig(Char(j+55)) ELSE
BEGIN NEW dig(')');
WHILE j NE 0 DO
BEGIN NEW dig(Char(Mod(j,10)+48)); j:= j//10 END;
NEW dig('(');
END unusual base;
i:= i//base;
END loop;
IF neg THEN NEW dig('-');
t:- Blanks(ndig);
WHILE xdig =/= NONE DO
BEGIN t.Putchar(xdig.c); xdig:- xdig.next END;
t.Setpos(1);
radix:- t
END radix;