Temperature conversion/REXX: Difference between revisions

m
added the COMMA subroutine to add commas to output.
(added the unabridged version of the REXX program.)
 
m (added the COMMA subroutine to add commas to output.)
Line 1:
This is the unabridged version of the REXX program to solve the Rosetta Code task of   ''Temperature conversion''.
=={{header|REXX}}
<lang rexx>/*REXX program converts temperatures for a number of temperature scales.*/
call e /*let's see the precision we have*/
Line 156 ⟶ 157:
/*──────────────────────────────────$ subroutine────────────────────────*/
$: procedure; showDig=8 /*only show 8 significant digits.*/
_=comma(format(arg(1), , showDig)/1 ) /*format # 8 digs past dec. point.and add ,*/
p=pos(.,_) /*find position of decimal point.*/
/* [↓] align integers with FP #s.*/
Line 162 ⟶ 163:
else _=_ || left('',5+showDig-length(_)+p) /*has " " */
return right(_,60) /*return the re-formatted arg. */
/*──────────────────────────────────COMMA subroutine────────────────────*/
comma: procedure; parse arg _,c,p,t,s /*get number and optional options*/
arg ,cU . /*get an uppercase version of C.*/
c=word(c ',', 1) /*get the commatizing char(s).*/
if cU=='BLANK' then c=' ' /*special case for a "blank" sep.*/
o=word(p 3, 1) /*get the optional period length.*/
p=abs(o) /*get the positive period length.*/
t=word(t 999999999, 1) /*get max# of "commas" to insert.*/
s=word(s 1, 1) /*get optional start position. */
 
if \datatype(p,'W') | \datatype(t,"W") | \datatype(s,'W') |,
t<1 | s<1 | p==0 | arg()>5 then return _ /*invalid options?*/
 
n=_'.9'; #=123456789; k=0 /*define some handy-dandy vars. */
 
if o<0 then do /*using a negative period length.*/
b=verify(_,' ', , s) /*position of 1st blank in string*/
e=length(_) - verify(reverse(_), ' ') + 1 - p
end
else do /*using a positive period length.*/
b=verify(n, #, "M", s) /*position of 1st useable digits.*/
z=max(1, verify(n, #"0.", 'M', s))
e=verify(n, #'0', , max(1, verify(n, #"0.", 'M', s))) - p - 1
end
 
if e>0 & b>0 then do j=e to b by -p while k<t /*commatize the digs*/
_=insert(c, _, j) /*comma spray ──� #.*/
k=k+1 /*bump commatizing. */
end /*j*/
return _
/*──────────────────────────────────SCALENAME subroutine────────────────*/
scaleName: parse arg y /*abbreviations ──► shortname. */
Line 302 ⟶ 333:
when abbrev('JACOBSHOLBORN' , yU,2) |,
abbrev('JACOBS-HOLBORN' , yU,2) then sn='JACOBS-HOLBORN'
when abbrev('KALVIN' , yU,2) |, /* 27% misspelled.*/
abbrev('KERLIN' , yU) |, /* 18% misspelled.*/
abbrev('KEVEN' , yU) |, /* 9% misspelled.*/