Temperature conversion/REXX: Difference between revisions

m
added whitespace.
(→‎{{header|REXX}}: condensed the COMMA function, changed comments, indenations, and whitespace, added ability to not list certain temperature scales.)
m (added whitespace.)
 
(25 intermediate revisions by 2 users not shown)
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*/
numeric digits length(e) /*big digits for Planck & Daltons*/
parse arg tList /*get specified temperature lists*/
 
Note that conversion from/to the &nbsp; '''Dalton''' &nbsp; temperature scale requires natural logarithms &nbsp; ('''ln'''), &nbsp; and the &nbsp; '''pow''' &nbsp; function.
do until tList='' /*process a list of temperatures.*/
 
parse var tList x ',' tList /*temps are separated by commas. */
 
x=translate(x,'((',"[{") /*support other grouping symbols.*/
No commenting/explaining was affixed to the higher math functions because it would detract from the logic of the main program.
x=space(x); parse var x z '(' /*handle any comments (if any). */
 
parse upper var z z ' TO ' ! . /*separate the TO option from #*/
 
parse var z z 'NOT' not . , noS noE /*separate NOT option from #.*/
<span style='font-family: "Linux Libertine",Georgia,Times,serif;font-size:150%;'>[[REXX]]</span><hr>
/* *xxx ◄───don't show scales that end in xxx */
 
if not\=='' then do /* xxx* ◄─── " " " " begin with xxx */
 
if left(not,1)=='*' then noE=substr(not,2)
<lang rexx>/*REXX program converts temperatures for fifty─eight different temperature scales. */
if right(not,1)=='*' then noS=left(not,length(not)-1)
/*
noL=length(noE || noS)
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
if noL==0 then call serr "illegal NOT keyword, no leading or trailing * specified."
 
tt tt
tt tt
tttttt tttttt
tttttt eeee mmm mm ppppp eeee rr rr aaaa tttttt uu uu rr rr eee
tt eeeeee mmmmmmmm pppppp eeeeee rrrrrr aaaaa tt uu uu rrrrrr eeeeee
tt ee ee mm mm mm pp pp ee ee rrr rr aa tt uu uu rrr rr ee ee
tt eeeeee mm mm mm pp pp eeeeee rr aaaaaa tt uu uu rr eeeeee
tt eeeeee mm mm mm pppppp eeeeee rr aaaaaaa tt uu uu rr eeeeee
tt tt ee mm mm mm ppppp ee rr aa aa tt tt uu uu rr ee
ttttt eeeee mm mm mm pp eeeee rr aaaaaaa ttttt uuuuuu rr eeeee
ttt eee mm mm mm pp eee rr aaaaaaa ttt uuu uu rr eee
pp
pp
 
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
*/
 
 
call e /*let's see the precision we can use. */
numeric digits length(e) - 1 /*big digits for Planck & Dalton scale.*/
/*subtract one for the decimal point.*/
parse arg tList /*get the specified temperature lists. */
tList= space(tList) /*elide any and all superfluous blanks.*/
 
do until tList='' /*process the list of temperatures. */
parse var tList x ',' tList /*temperatures are separated by commas.*/
x= translate(x, '(((', "[{«") /*support other grouping symbols. */
x= space(x) /*elide any and all superfluous blanks.*/
parse var x z '(' /*handle any comments (if there're any)*/
parse upper var z z ' TO ' ! . /*separate the TO option from number.*/
parse upper var z z 'NOT' not . , noS noE /*separate NOT option from number. */
/*for the NOT keyword, see (below).*/
/* *xxx ◄───don't show scales that end in xxx */
/* xxx* ◄─── " " " " begin with xxx */
if not\=='' then do
if left(not, 1) == '*' then noE= substr(not, 2)
if right(not, 1) == '*' then noS= left(not, length(not) - 1)
noL= length(noE || noS)
if noL==0 then call serr ,
"illegal NOT keyword, no leading or trailing * specified."
end
 
if !=='' then !='ALL'; all=!=='"ALL'" /*allownothing specificationspecific, so choose of "TOALL". opt*/
 
all= (!=='ALL') /*allows specification of the "TO" opt.*/
 
if z=='' then call serr 'no arguments were specified.'
 
_=verify(z, '+-.0123456789') /*a list of valid number thingys.*/
_= verify(z, '+-.0123456789') /*list of valid decimal digs & thingys.*/
n=z
n= z /*obtain a "backup" copy of Z (number).*/
 
if _\==0 then do
if _==1 then call serr 'illegal temperature:' z
n= left(z, _-1) /*pick offobtain the number (hopefully). */
u= strip( substr(z, _) ) /*pick offobtain the temperature unit. */
end
else u= 'k' /*assume kelvin as per task req.requirement*/
/* ────── */
if \datatype(n, 'N') then call serr "illegal number:" n
 
if \all then do /*there is a TO ααα temp. scale. */
call scaleName ! /*process the TO temp. abbreviation.*/
!= sn /*assign the full temperature name to !*/
end /*! now contains temp scale full name.*/
 
call scaleName u /*allow alternate temp. scale spellings*/
call convert2Fahrenheit /*convert a temperature ──► Fahrenheit.*/
 
say right(' ' x, 79, "─") /*show original value & scale (for sep)*/
 
call convert2specific /*convert Fahrenheit ──► specific temp,*/
end /*until tlist*/ /*this is a biggish DO loop. */
 
 
exit /*stick a fork in it, we're all done. */
 
 
/*──────────────────────────────────────────────────────────────────────────────────────*/
$: procedure; showDig= 8 /*only show 8 significant decimal digs.*/
_= commas( format( arg(1), , showDig ) / 1 ) /*format# 8 digits past . and add comma*/
p= pos(., _) /*find position of the decimal point. */
/* [↓] align integers with FP numbers.*/
if p==0 then _= _ || left('', 5 + showDig + 1) /*no decimal point.*/
else _= _ || left('', 5 + showDig - length(_) + p) /*has " " */
 
return right(_, max(60, length(_) ) ) /*return the re─formatted argument (#).*/
 
 
/*────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
if \datatype(n,'N') then call serr 'illegal number:' n
convert2Fahrenheit: if \all then do /*there is a /*convert TON ααα──► ºF scale temperatures. */
call scaleName ! /*process the TO abbreviation*/
!=sn /*assign the full name to ! */
end /* ! now contains scale full name*/
call scaleName u /*allow alternate scale spellings*/
 
select /*convert ──►[↓] °Ffifty-eight temperature temperaturesscales. */
select
when sn=='ABSOLUTE' then F= n * 9/5 - 459.67
when sn=='AMONTON' then F= n * 8.37209 - 399.163
when sn=='BARNSDORF' then F= n * 6.85714 + 6.85714
when sn=='BEAUMUIR' then F= n * 2.22951 + 32
when sn=='BENART' then F= n * 1.43391 + 31.2831
when sn=='BERGEN' then F=(n + 23.8667) * 15/14
when sn=='BRISSEN' then F= n * 32/15 + 32
when sn=='CELSIUS' then F= n * 9/5 + 32 /*a single C is taken as Celsius.*/
Line 50 ⟶ 119:
when sn=='CRUQUIUS' then F= n * 0.409266 - 405.992
when sn=='DALENCE' then F= n * 2.7 + 59
when sn=='DALTON' then F= 273.15 * pow(273.15 / 273.15, n / 100) * 1.8 - 459.67
when sn=='DANIELL' then F= n * 7.27194 + 55.9994
when sn=='DE LA HIRE' then F=(n - 3) / 0.549057
when sn=='DE LA VILLE' then F=(n + 6.48011) / 0.985568
when sn=='DELISLE' then F=212 - n * 6/5
when sn=='DELISLE OLD' then F=212 - n * 1.58590197
when sn=='DE LUC' then F=(n + 14) * 16/7
when sn=='DE LYON' then F=(n + 17.5) * 64/35
when sn=='DE REVILLAS' then F=212 - n * 97/80
when sn=='DERHAM' then F= n / 0.38444386 - 188.578
when sn=='DERHAM OLD' then F= n * 3 + 4.5
when sn=='DE SUEDE' then F=(n + 17.6666) * 150/83
when sn=='DE VILLENEUVE' then F=(n + 23.7037) / 0.740741
when sn=='DU CREST' then F=(n + 37.9202) / 0.650656
when sn=='EDINBURGH' then F= n * 4.6546 - 6.40048
when sn=='ELECTRON VOLTS' then F= n * 20888.1 - 459.67
when sn=='FAHRENHEIT' then F= n
when sn=='FAHRENHEIT OLD' then F= n * 20/11 - 89.2727
when sn=='FLORENTINE LARGE' then F=(n + 7.42857) / 0.857143
when sn=='FLORENTINE MAGNUM' then F=(n + 73.9736 ) / 1.50659
when sn=='FLORENTINE SMALL' then F=(n - 1.38571) / 0.378571
when sn=='FOWLER' then F= n * 0.640321 + 53.7709
when sn=='FRICK' then F= n * 200/251 + 58.5339
Line 83 ⟶ 152:
when sn=='NEWTON' then F= n * 60/11 + 32
when sn=='OERTEL' then F= n + n - 32
when sn=='PLANCK' then F= n * 1.416833e32 * 9/5 - 459.67
when sn=='RANKINE' then F= n - 459.67 /*a single R is taken as Rankine.*/
when sn=='REAUMUR' then F= n * 9/4 + 32
Line 90 ⟶ 159:
when sn=='ROMER' then F=(n - 7.5) * 27/4 + 32
when sn=='ROSENTHAL' then F= n * 45/86 - 453.581
when sn=='ROYAL SOCIETY' then F=(n -122.82) * -50/69
when sn=='SAGREDO' then F= n * 0.3798 - 5.98
when sn=='SAINT-PATRICE' then F= n * 2.62123 + 115.879
Line 100 ⟶ 169:
end /*select*/
 
return
K = (F + 459.67) * 5/9 /*compute temperature to kelvins.*/
 
a =(1e || (-digits()%2)-digits()%20) /*mininum number for Dalton temp.*/
 
eV=(F + 459.67) / 20888.1 /*compute number electron volts. */
/*─────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
say right(' ' x, 79, "─") /*show original value &scale,sep.*/
convert2specific: if ?('AMONTON') then say $( ( F + 399.163 ) / 8.37209 /*convert ºF ──► xxx ) 'Amonton'temperatures.*/
 
if ?('BARNSDORF') then say $( ( F - 6.85715) / 6.85715 ) 'Barnsdorf'
ifK ?('BEAUMUIR')= then say $(F (+ F459.67) * - 5/9 32 ) / 2.22951 /*compute temperature in )kelvin scale. 'Beaumuir'*/
a = (1e || (-digits() % 2) - digits() % 20) /*minimum number for Dalton temperature*/
if ?('BENART') then say $( ( F - 31.2831 ) / 1.43391 ) 'Benart'
eV = if ?('BERGEN') then say $( ( F + 459.67) * 14/15 20888.1 ) - 23.8667 /*compute the )number of 'Bergen'electron volts.*/
 
if ?('BRISSON') then say $( ( F - 32 ) * 15/32 ) 'Brisson'
 
if ?('CELSIUS') then say $( ( F - 32 ) * 5/9 ) 'Celsius'
if ?('CIMENTOABSOLUTE') then say $( ( F +k 4.54135) / 2.70677 ) 'Cimento'"Absolute"
if ?('CRUQUIUSAMONTON') then say $( ( F + 405399.992163 ) / 0 8.40926637209 ) 'Cruquius'"Amonton"
if ?('DALENCEBARNSDORF') then say $( ( F - 59 6.85715) / 2 6.7 85715 ) 'Dalence'"Barnsdorf"
if ?('DALTONBEAUMUIR') then if k>a then say $(100*ln (k/273.15 F - 32 ) /ln(373.15/273 2.15)22951 ) 'Dalton'"Beaumuir"
if ?('BENART') then say $( ( F - 31.2831 ) / 1.43391 else say right('-infinity ', 60 ) 'Dalton'"Benart"
if ?('DANIELLBERGEN') then say $( ( F -* 14/15 55.9994 ) /- 723.271948667 ) 'Daniell'"Bergen"
if ?('DE LA HIREBRISSON') then say $( ( F *- 32 0.549057 + 3 ) * 15/32 ) 'De) la Hire'"Brisson"
if ?('DE LA VILLECELSIUS') then say $( ( F *- 32 0.985568 - 6.48011 ) * 5/9 ) 'De la Ville' ) "Celsius"
if ?('DELISLECIMENTO') then say $( ( 212 - F + 4.54135) * 5/6 2.70677 ) 'Delisle'"Cimento"
if ?('DELISLE OLDCRUQUIUS') then say $( ( 212 - F + 405.992 ) / 1 0.58590197409266 ) 'Delisle OLD'"Cruquius"
if ?('DE LUCDALENCE') then say $( ( F *- 7/1659 -) 14/ 2.7 ) 'De Luc'"Dalence"
 
if ?('DE LYON') then say $( F * 35/64 - 17.5 ) 'De Lyon'
if ?('DE REVILLASDALTON') then say $( ( 212 -then Fif K>a then say ) $(100* 80ln(k/273.15)/ln(373.15/97 273.15) ) 'De Revillas'"Dalton"
if ?('DERHAM') then say $( F * 0.38444386 + 72.4978 else say right("-infinity ", 60) 'Derham' "Dalton"
 
if ?('DERHAM OLD') then say $( ( F - 4.5 ) / 3 ) 'Derham OLD'
if ?('DE VILLENEUVEDANIELL') then say $( ( F *- 0 55.7407419994 ) / - 237.7037 27194 ) 'De Villeneuve'"Daniell"
if ?('DE SUEDELA HIRE') then say $( F * 83/150 0.549057 + 3 - 17.6666 ) '"De Suede'la Hire"
if ?('DUDE LA CRESTVILLE') then say $( F * 0.650656985568 - - 376.9202 48011 ) 'Du"De Crest'la Ville"
if ?('EDINBURGHDELISLE') then say $( ( 212 - F + 6.40048 ) * 5/6 4.6546 ) 'Edinburgh'"Delisle"
if ?('ELECTRONDELISLE VOLTSOLD') then say $( ( 212 - eV F ) / 1.58590197 ) 'electron"Delisle volt's(eV)OLD"
if ?('FAHRENHEITDE LUC') then say $( F * 7/16 - 14 ) "De ) 'Fahrenheit'Luc"
if ?('FAHRENHEITDE OLDLYON') then say $( F * 2035/1164 - 89 17.27275 ) 'Fahrenheit"De OLD'Lyon"
if ?('FLORENTINEDE LARGEREVILLAS') then say $( ( 212 - F * 0.857143 - 7.42857) * 80/97 ) 'Florentine"De large'Revillas"
if ?('FLORENTINE MAGNUMDERHAM') then say $( F * 10.5065938444386 + - 7372.97364978 ) 'Florentine Magnum'"Derham"
if ?('FLORENTINEDERHAM SMALLOLD') then say $( ( F *- 04.3785715 ) / 3 + 1.38571 ) 'Florentine"Derham small'OLD"
if ?('FOWLERDE VILLENEUVE') then say $( ( F -* 530.7709740741 ) / - 0 23.6403217037 ) 'Fowler'"De Villeneuve"
if ?('FRICKDE SUEDE') then say $( ( F -* 83/150 58.5338 ) * 251/200 - 17.6666 ) 'Frick'"De Suede"
if ?('GASDU MARKCREST') then say $( ( F -* 2500.650656 - ) * 037.04 9202 ) 'gas"Du mark'Crest"
if ?('GOUBERTEDINBURGH') then say $( ( F + 32 6.40048) / ) * 04.5 6546 ) 'Goubert'"Edinburgh"
if ?('HALESELECTRON VOLTS') then say $( eV then say $( ( F - 32 ) / 1.2 ) 'Hales'"electron volt"s(eV)
if ?('HANOWFAHRENHEIT') then say $( ( F + 10.6672 ) / 1.06668 ) 'Hanow'"Fahrenheit"
if ?('HAUKSBEEFAHRENHEIT OLD') then say $( ( F -* 20/11 88.16 ) * 25/18- 89.2727 ) 'Hauksbee'"Fahrenheit OLD"
if ?('JACOBS-HOLBORNFLORENTINE LARGE') then say $( ( F + * 530.4366857143 ) * 71/18- 7.42857 ) 'Jacobs-Holborn'"Florentine large"
if ?('KELVINFLORENTINE MAGNUM') then say $( F k * 1.50659 - 73.9736 ) "Florentine ) 'kelvin's(k)Magnum"
if ?('LEIDENFLORENTINE SMALL') then say $( F /* 10.8378571 + + 2351.222 38571 ) 'Leiden'"Florentine small"
if ?('NEWTONFOWLER') then say $( ( F - 32 53.7709 ) * 11/60 0.640321 ) 'Newton'"Fowler"
if ?('OERTELFRICK') then say $( ( F + 32 - 58.5338 ) * 0.5 251/200 ) 'Oertel'"Frick"
if ?('PLANCKGAS MARK') then say $( ( F +- 250 459.67 ) * 5/90.04 / 1.416833e32 ) 'Planck'"gas mark"
if ?('RANKINEGOUBERT') then say $( ( F + 459.67 32 ) * 0.5 ) 'Rankine'"Goubert"
if ?('REAUMURHALES') then say $( ( F - 32 ) */ 4/91.2 ) 'Reaumur'"Hales"
if ?('RICHTERHANOW') then say $( ( F + 710.452056672 ) */ 73/160 1.06668 ) 'Richter'"Hanow"
if ?('RINALDINIHAUKSBEE') then say $( ( F - 3288.16 ) * ) 25/ 15 18 ) 'Rinaldini'"Hauksbee"
if ?('ROMERJACOBS-HOLBORN') then say $( ( F -+ 3253.4366 ) * 71/18 ) * 7/24 + 7.5 ) 'Romer'"Jacobs-Holborn"
if ?('ROSENTHALKELVIN') then say $( ( F +k 453.581 ) * 86/45 ) 'Rosenthal'"kelvin"s(k)
if ?('ROYAL SOCIETYLEIDEN') then say $( F * -69/50 1.8 + 122.82 + 235.222 ) 'Royal Society of) London' "Leiden"
if ?('SEGREDONEWTON') then say $( ( F +- 32 5.98 ) * 11/60 0.3798 ) 'Segredo'"Newton"
if ?('SAINT-PATRICEOERTEL') then say $( ( F -+ 32 115.879 ) /* 20.621235 ) 'Saint-Patrice'"Oertel"
if ?('STUFEPLANCK') then say $( ( F -+ 257459.67 ) * ) 5/9 / 45 1.416833e32 ) 'Stufe'"Planck"
if ?('SULZERRANKINE') then say $( ( F -+ 33459.233467 ) / 1.14595 ) 'Sulzer'"Rankine"
if ?('THERMOSTATREAUMUR') then say $( ( F - 32 ) /* 54 4/9 ) 'Thermostat'"Reaumur"
if ?('WEDGWOODRICHTER') then say $( ( F -+ 516.2 7.45205) * ) 73/160 44.7429295 ) 'Wedgwood'"Richter"
if ?('RINALDINI') then say $( ( F - 32 ) / 15 ) "Rinaldini"
end /*until tlist ···*/
if ?('ROMER') then say $( ( F - 32 ) * 4/27 + 7.5 ) "Romer"
if ?('ROSENTHAL') then say $( ( F + 453.581 ) * 86/45 ) "Rosenthal"
if ?('ROYAL SOCIETY') then say $( F * -69/50 + 122.82 ) "Royal Society of London"
if ?('SAGREDO') then say $( ( F + 5.98 ) / 0.3798 ) "Segredo"
if ?('SAINT-PATRICE') then say $( ( F - 115.879 ) / 2.62123 ) "Saint-Patrice"
if ?('STUFE') then say $( ( F - 257 ) / 45 ) "Stufe"
if ?('SULZER') then say $( ( F - 33.2334 ) / 1.14595 ) "Sulzer"
if ?('THERMOSTAT') then say $( ( F - 32 ) / 54 ) "Thermostat"
if ?('WEDGWOOD') then say $( ( F - 516.2 ) / 44.7429295 ) "Wedgwood"
 
return
 
 
/*──────────────────────────────────────────────────────────────────────────────────────────────────*/
scaleName: parse arg y /*abbreviations ──► temp. short name.*/
yU= translate(y, '-eE', "_éÉ") /*translate some accented characters. */
upper yU /*uppercase version of temperature unit*/
 
if left(yU, 7)=='DEGREES' then yU=substr(yU, 8) /*is this a redundant "degrees" ? */
if left(yU, 6)=='DEGREE' then yU=substr(yU, 7) /* " " " " "degree" ? */
 
yU= strip(yU) /*elide all leading & trailing blanks. */
_= length(yU) /*obtain the length of the yU value. */
 
if right(yU,1)=='S' & _>1 then yU=left(yU, _-1) /*remove any trailing plural(s). */
 
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────$ subroutine────────────────────────*/
$: procedure; showDig=8 /*only show 8 significant digits.*/
_=comma(format(arg(1), , showDig)/1) /*format# 8 digs past . and add ,*/
p=pos(.,_) /*find position of decimal point.*/
/* [↓] align integers with FP #s.*/
if p==0 then _=_ || left('',5+showDig+1) /*no decimal point.*/
else _=_ || left('',5+showDig-length(_)+p) /*has " " */
return right(_,60) /*return the re-formatted arg. */
/*──────────────────────────────────SCALENAME subroutine────────────────*/
scaleName: parse arg y /*abbreviations ──► shortname. */
yU=translate(y,'-eE',"_éÉ") /*uppercase version of temp unit.*/
upper yU /*uppercase version of temp unit.*/
if left(yU,7)=='DEGREES' then yU=substr(yU,8) /*redundant "degrees"? */
if left(yU,6)=='DEGREE' then yU=substr(yU,7) /* " "degree" ? */
yU=strip(yU) /*elide blanks at ends.*/
_=length(yU) /*obtain the yU length.*/
if right(yU,1)=='S' & _>1 then yU=left(yU,_-1) /*elide trailing plural*/
 
select /*change abbreviations ──► shortname. */
when abbrev('AMONTONABSOLUTE' , yU, yU1) then sn='AMONTON' "ABSOLUTE"
when abbrev('AMONTON' , yU) then sn= "AMONTON"
when abbrev('BARNDORF' , yU,2) |,
abbrev('BARNSDORF' , yU,2) then sn=' "BARNSDORF'"
when abbrev('BEAUMIUR' , yU,3) |,
abbrev('BEAUMUIR' , yU,3) then sn=' "BEAUMUIR'"
when abbrev('BENERT' , yU,3) |,
abbrev('BENART' , yU,3) then sn=' "BENART'"
when abbrev('BRISSEN' , yU,3) |,
abbrev('BRISSON' , yU,3) then sn=' "BRISSEN'"
when abbrev('BURGEN' , yU,3) |,
abbrev('BURGAN' , yU,3) |,
abbrev('BERGAN' , yU,3) |,
abbrev('BERGEN' , yU,3) then sn=' "BERGEN'"
when abbrev('CENTIGRADE' , yU) |,
abbrev('CENTRIGRADE' , yU) |, /* 50% misspelled.*/
Line 210 ⟶ 287:
abbrev('CELISU' , yU) |, /* 1% misspelled.*/
abbrev('CELSU' , yU) |, /* 1% misspelled.*/
abbrev('CELSIUHECTOGRADE' , yU) |, then sn='CELSIUS'
abbrev('CELSIU' , yU) then sn= "CELSIUS"
when abbrev('CIMANTO' , yU,2) |,
abbrev('CIMENTO' , yU,2) then sn=' "CIMENTO'"
when abbrev('CRUQUIOU' , yU,2) |,
abbrev('CRUQUIO' , yU,2) |,
abbrev('CRUQUIU' , yU,2) then sn=' "CRUQUIU'"
when abbrev('DALANCE' , yU,4) |,
abbrev('DALENCE' , yU,4) then sn=' "DALENCE'"
when abbrev('DANELLE' , yU,3) |,
abbrev('DANEAL' , yU,3) |,
Line 225 ⟶ 303:
abbrev('DANYAL' , yU,3) |,
abbrev('DANYEL' , yU,3) |,
abbrev('DANIELL' , yU,3) then sn=' "DANIELL'"
when abbrev('DALTON' , yU,3) then sn=' "DALTON'"
when abbrev('DELAHIRE' , yU,7) |,
abbrev('LAHIRE' , yU,4) |,
abbrev('HIRE' , yU,2) |,
abbrev('DE-LA-HIRE' , yU,7) then sn=' "DE LA HIRE'"
when abbrev('DELAVILLE' , yU,7) |,
abbrev('LAVILLE' , yU,3) |,
abbrev('VILLE' , yU,1) |,
abbrev('VILLA' , yU,1) |,
abbrev('DE-LA-VILLE' , yU,7) then sn=' "DE LA VILLE'"
when abbrev('DELISLE' , yU,3) then sn=' "DELISLE'"
when abbrev('DELISLE-OLD' , yU,8) |,
abbrev('OLDDELISLE' , yU,6) |,
abbrev('DELISLEOLD' , yU,8) then sn=' "DELISLE OLD'"
when abbrev('DELUC' , yU,4) |,
abbrev('LUC' , yU,2) |,
abbrev('DE-LUC' , yU,5) then sn=' "DE LUC'"
when abbrev('DELYON' , yU,4) |,
abbrev('LYON' , yU,2) |,
abbrev('DE-LYON' , yU,5) then sn=' "DE LYON'"
when abbrev('DEREVILLA' , yU,3) |,
abbrev('DEREVILA' , yU,3) |,
abbrev('REVILLA' , yU,3) |,
abbrev('DE-REVILLA' , yU,4) |,
abbrev('DE-REVILLA' , yU,5) then sn=' "DE REVILLAS'"
when abbrev('DEVILLENEUVE' , yU,3) |,
abbrev('DE-VILLENEUVE' , yU,4) then sn=' "DE VILLENEUVE'"
when abbrev('DURHAM' , yU,3) |,
abbrev('DERHAM' , yU,4) then sn=' "DERHAM'"
when abbrev('OLDDURHAM' , yU,5) |,
abbrev('OLDDERHAM' , yU,6) |,
abbrev('DERHAM-OLD' , yU,4) |,
abbrev('DERHAMOLD' , yU,4) then sn=' "DERHAM OLD'"
when abbrev('DE-SUEDE' , yU,4) |,
abbrev('DESUEDE' , yU,4) then sn=' "DE SUEDE'"
when abbrev('DU-CREST' , yU,2) |,
abbrev('DUCREST' , yU,2) then sn=' "DU CREST'"
when abbrev('EDENBURGH' , yU,2) |,
abbrev('EDINBURGH' , yU,2) then sn=' "EDINBURGH'"
when abbrev('EVOLT' , yU,2) |,
abbrev('ELECTRONVOLT' , yU,2) then sn=' "ELECTRON VOLTS'"
when abbrev('FARENHEIT' , yU) |, /* 39% misspelled.*/
abbrev('FARENHEIGHT' , yU) |, /* 15% misspelled.*/
Line 282 ⟶ 360:
abbrev('FARINHEIT' , yU) |, /* 1% misspelled.*/
abbrev('FARANHITE' , yU) |, /* 1% misspelled.*/
abbrev('FAHRENHEIT' , yU) then sn=' "FAHRENHEIT'"
when abbrev('OLDFAHRENHEIT' , yU,4) |,
abbrev('FAHRENHEIT-OLD' , yU,13) |,
abbrev('FAHRENHEITOLD' , yU,13) then sn=' "FARHENHEIT OLD'"
when abbrev('FLORENTINE-LARGE' , yU,12) |,
abbrev('LARGE-FLORENTINE' , yU,7) |,
abbrev('LARGEFLORENTINE' , yU,6) |,
abbrev('FLORENTINELARGE' , yU,12) then sn=' "FLORENTINE LARGE'"
when abbrev('FLORENTINE-MAGNUM' , yU,2) |,
abbrev('MAGNUM-FLORENTINE' , yU,3) |,
abbrev('MAGNUMFLORENTINE' , yU,3) |,
abbrev('FLORENTINEMAGNUM' , yU,2) then sn=' "FLORENTINE MAGNUM'"
when abbrev('FLORENTINE-SMALL' , yU,13) |,
abbrev('SMALL-FLORENTINE' , yU,7) |,
abbrev('SMALLFLORENTINE' , yU,6) |,
abbrev('FLORENTINESMALL' , yU,13) then sn=' "FLORENTINE SMALL'"
when abbrev('FOULER' , yU,2) |,
abbrev('FOWLOR' , yU,2) |,
abbrev('FOWLER' , yU,2) then sn=' "FOWLER'"
when abbrev('FRICK' , yU,2) then sn=' "FRICK'"
when abbrev('GAS-MARK' , yU,2) |,
abbrev('GASMARK' , yU,2) then sn=' "GAS MARK'"
when abbrev('GOUBERT' , yU,2) then sn=' "GOUBERT'"
when abbrev('HAIL' , yU,3) |,
abbrev('HALE' , yU,3) then sn=' "HALES'"
when abbrev('HANOW' , yU,3) then sn=' "HANOW'"
when abbrev('HUCKSBEE' , yU,3) |,
abbrev('HAWKSBEE' , yU,3) |,
abbrev('HAUKSBEE' , yU,3) then sn=' "HAUKSBEE'"
when abbrev('JACOBSHOLBORN' , yU,2) |,
abbrev('JACOBS-HOLBORN' , yU,2) then sn=' "JACOBS-HOLBORN'"
when abbrev('KALVIN' , yU) |, /* 27% misspelled.*/
abbrev('KERLIN' , yU) |, /* 18% misspelled.*/
abbrev('KEVEN' , yU) |, /* 9% misspelled.*/
abbrev('KELVIN' , yU) then sn=' "KELVIN'"
when abbrev('LAYDEN' , yU) |,
abbrev('LEIDEN' , yU) then sn=' "LEIDEN'"
when abbrev('NEUTON' , yU) |, /*100% misspelled.*/
abbrev('NEWTON' , yU) then sn=' "NEWTON'"
when abbrev('ORTEL' , yU) |,
abbrev('OERTEL' , yU) then sn=' "OERTEL'"
when abbrev('PLACK' , yU) |, /*100% misspelled.*/
abbrev('PLANC' , yU) |, /* misspelled.*/
abbrev('PLANK' , yU) |, /* misspelled.*/
abbrev('PLANCK' , yU) then sn=' "PLANCK'"
when abbrev('RANKINE' , yU, 1) then sn=' "RANKINE'"
when abbrev('REAUMUR' , yU, 2) then sn=' "REAUMUR'"
when abbrev('RICKTER' , yU, 3) |,
abbrev('RICHTER' , yU, 3) then sn=' "RICHTER'"
when abbrev('RINALDINI' , yU, 3) then sn=' "RINALDINI'"
when abbrev('ROEMER' , yU, 3) |,
abbrev('ROMER' , yU, 3) then sn=' "ROMER'"
when abbrev('ROSANTHAL' , yU, 3) |,
abbrev('ROSENTHAL' , yU, 3) then sn=' "ROSENTHAL'"
when abbrev('RSOL' , yU, 2) |,
abbrev('RSL' , yU, 2) |,
abbrev('ROYALSOCIETYOFLONDON' , yU, 3) |,
abbrev('ROYAL-SOCIETY-OF-LONDON' , yU, 3) then sn=' "ROYAL SOCIETY'"
when abbrev('SAGREDO' , yU, 3) then sn=' "SAGREDO'"
when abbrev('ST.-PATRICE' , yU, 3) |,
abbrev('ST.PATRICE' , yU, 3) |,
abbrev('SAINTPATRICE' , yU, 3) |,
abbrev('SAINT-PATRICE' , yU, 3) then sn=' "SAINT-PATRICE'"
when abbrev('STUFFE' , yU, 3) |,
abbrev('STUFE' , yU, 3) then sn=' "STUFE'"
when abbrev('SULTZER' , yU, 2) |,
abbrev('SULZER' , yU, 2) then sn=' "SULZER'"
when abbrev('WEDGEWOOD' , yU) |,
abbrev('WEDGWOOD' , yU) then sn=' "WEDGWOOD'"
 
otherwise call serr 'illegal temperature scale:' y
end /*select*/
 
 
return
 
/*──────────────────────────────────one─liner subroutines───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
 
?: parse arg y; if not\=='' then do; if noS\=='' then if left(y,noL)==noS then return 0; if noE\=='' then if right(y,noL)==noE then return 0; end; if all | y==! then return 1; return 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
comma: procedure; parse arg _,c,p,t,s; arg ,U .; c=p(c ',');if U=='BLANK' then c=' '; o=p(p 3);p=abs(o); t=p(t 1e7); s=p(s 1);if \isInt(p)|\isInt(t)|\isInt(s)|t<1|s<1|p==0|arg()>5 then return _;n=_'.9';#=123456789; k=0;call comma.;return comma..()
?: parse arg y 1 yu
comma.: n=_'.9'; #=123456789; k=0; if o<0 then do; b=verify(_,' ',,s); e=length(_)-verify(reverse(_),' ')+1-p; end; else do; b=verify(n,#,"M",s); z=max(1,verify(n,#"0.",'M',s)); e=verify(n,#'0',,max(1,verify(n,#"0.",'M',s)))-p-1; end; return
upper yu
comma..: if e>0 & b>0 then do j=e to b by -p while k<t; _=insert(c,_,j); k=k+1; end; return _
if not\=='' then do
e: e = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932; return e
if noS\=="" then if left(yu, noL)==noS then return 0
isInt: return datatype(arg(1), 'W') /*is the argument a whole number (integer)?*/
exp: procedure; parse arg x; ix=x%1; if abs(x-ix)>.5 then ix=ix+sign(x); x=x-ix; z=1; _=1; w=z; do j=1; _=_*x/j; z=(z+_)/1; if znoE\==w'' then leave;w=z;end;if z\right(yu, noL)==0noE then z=z*e()**ix;return z/10
end
ln: procedure; parse arg x; call e; ig=x>1.5; is=1-2*(ig\==1); ii=0; xx=x; return ln..()
 
ln..: do while ig & xx>1.5 | \ig & xx<.5;_=e;do k=-1;iz=xx*_**-is;if k>=0 & (ig & iz<1 | \ig & iz>.5) then leave;_=_*_;izz=iz;end;xx=izz; ii=ii+is*2**k; end; x=x*e**-ii-1; z=0;_=-1;p=z;do k=1; _=-_*x; z=z+_/k; if z=p then leave;p=z; end; return z+ii
if all | y==! then return 1
p: return subword(arg(1), 1, max(1, words(arg(1))-1))
pow: procedure; parse arg x,y; if y=0 then return 1; if x=0 then return 0; if isInt(y) then return x**y; if isInt(1/y) then return root(x,1/y,f); return pow_()0
 
pow_: if abs(y//1)=.5 then return sqrt(x)**sign(y)*x**(y%1); return exp(y*ln(x))
 
root: procedure; parse arg x,y; if x=0 | y=1 then return x; if isInt(y) then return rooti(x,y); _=sqrt(x); if y<0 then _=1/_; return _
/*──────────────────────────────────────────────────────────────────────────────────────*/
rooti: procedure; parse arg x,y; if x=0 | y=1 then return x; n=y<0; y=abs(y); numeric digits digits()+2; z=abs(x); g=(z+1)/y; m=y-1; numeric fuzz 2; do forever; _=(m*g**y+z)/y/g**m; if _=g then leave; g=_; end; _=g*sign(x); if n then _=1/_; return _
scommas: procedure; parse arg _ if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizerinsert commas in a number. */
n= _'.9' /*added suffix for VERIFY BIF.*/
serr: say; say '***error!***'; say; say arg(1); say; exit 13
#= 123456789 /*a nifty handy-dandy literal.*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); p=d; m.=9; numeric digits 9; g=sqrt.(); m.0=d; m.1=d; do j=2 while p>9; m.j=p; p=p%2+1; end; do k=j+5 to 0 by -1; numeric digits m.k; g=.5*(g+x/g); end; numeric digits d; return (g/1)i
sqrt.: i=; b= ifverify(n, x<0#, "M") then do; x=-x; i='i'; end; numeric form; parse value format(x,2,1,,0) 'E0' with g 'E'/*find _beginning .;of a number. return g*.5'E'_%2</lang>
e= verify(n, #'0', , verify(n, #"0.", 'M') ) - 4 /* " end " " " */
 
do j=e to b by -3 /*insert commas right─to─left.*/
_= insert(",", _, j) /*insert a comma every period.*/
end /*j*/
 
return _
 
 
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x /*obtain the target of SQRT. */
if x=0 then return 0 /*Argument is zero? Return 0.*/
/*This function work for zero.*/
d= digits() /*get # of dec. digs, current.*/
m.= 9 /*set " " " " at start.*/
h= d+6 /*add 6 for rounding concerns.*/
numeric form /*right form of exponentiation*/
numeric digits /*start with nine numeric digs*/
 
/*a way of getting the expon. */
/*No exponent? Then add one. */
parse value format(x, 2, 1, , 0) 'E0' with g "E" _ .
/* [↓] halve the exponent. */
g=g * .5'e'_ % 2 /*a first best guess for sqrt,*/
/*which is 1/2 of the exponent*/
/* [↓] use min number of dec.*/
/* digs for early SQRTs. */
do j=0 while h>9
m.j= h /*calculate # of digits to use*/
h= h % 2 + 1 /*halving the exponent means */
end /*j*/ /* that it'll be doubled as */
/* the M. array will be */
/* processed backwards. [↓] */
do k=j+5 to 0 by -1 /*calculate higher precision. */
numeric digits m.k /*bump the decimal digits. */
g= (g + x / g) * .5 /*calculate SQRT approximation*/
end /*k*/
return g / 1 /*this normalizes the sqrt #. */
 
 
/*──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
?: parse arg y; if not\=='' then do; if noS\=="" then if left(y, noL)==noS then return 0; if noE\=='' then if right(y, noL)==noE then return 0; end; if all | y==! then return 1; return 0
e: e = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932; return e /*112 useful decimal digits. */
isInt: return datatype(arg(1), 'W') /*is the argument a whole number (integer)? */
exp: procedure; parse arg x; ix=x%1; if abs(x-ix)>.5 then ix=ix+sign(x); x=x-ix; z=1; _=1; w=z; do j=1; _=_*x/j; z=(z+_)/1; if z==w then leave; w=z; end; if z\==0 then z= z * e()**ix; return z/1
ln: procedure; parse arg x; call e; ig=x>1.5; is=1-2*(ig\==1); ii=0; xx=x; return ln..()
ln..: do while ig & xx>1.5 | \ig & xx<.5;_=e;do k=-1;iz=xx*_**-is;if k>=0 & (ig & iz<1 | \ig & iz>.5) then leave;_=_*_;izz=iz;end;xx=izz; ii=ii+is*2**k; end; x=x*e**-ii-1; z=0;_=-1;p=z;do k=1; _=-_*x;z=z+_/k; if z=p then leave;p=z; end; return z+ii
pow: procedure; parse arg x,y; if y=0 then return 1; if x=0 then return 0; if isInt(y) then return x**y; if isInt(1/y) then return root(x,1/y,f); return pow.()
pow.: if abs(y//1)=.5 then return sqrt(x)**sign(y)*x**(y%1); return exp(y*ln(x))
root: procedure; parse arg x 1 ox,y 1 oy; if x=0 | y=1 then return x; if isInt(y) then return rooti(x,y); _=sqrt(x); if y<0 then _=1/_; return _
rooti: x=abs(x); y=abs(y); a= digits() + 5; g=rootIg(); m= y-1; d=5; do until d==a; d=min(d+d, a); numeric digits d; o=0; do until o=g; o=g; g=format( (m*g**y+x) /y/g**m, , d-2); end; end; _= g * sign(ox); if oy<0 then _= 1/_; return _
rootIg: numeric form;parse value format(x,2,1,,0) 'E0' with ? 'E' _ .; return (? / y'E'_ % y) + (x>1)
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizer.*/
serr: say; say '***error***'; say; say arg(1); say; exit 13
</lang>