Conversion Utils #87

Parent #72Owner #29Flags readSource hellcore/hellcore.db

Aliases: Conversion Utils

15 verbs · 392 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
dd_to_dms dh_to_hmsthis none thisrxd#875
dms_to_dd hms_to_dhthis none thisrxd#877
rect_to_polarthis none thisrxd#876
polar_to_rectthis none thisrxd#876
F_to_C degF_to_degCthis none thisrxd#873
C_to_F degC_to_degFthis none thisrxd#873
convertthis none thisrxd#8726
_do_convertthis none thisrxd#8770
_try_metric_prefixthis none thisrxd#87111
_format_unitsthis none thisrxd#8715
K_to_C degK_to_degCthis none thisrxd#873
C_to_K degC_to_degKthis none thisrxd#873
F_to_R degF_to_degRthis none thisrxd#873
R_to_F degR_to_degFthis none thisrxd#873
_do_valuethis none thisrxd#875

Properties

PropertyDefinerFlagsOwnerValue
basic_units#87r#29
list of 9{"m", "kg", "s", "coul", "candela", "radian", "bit", "erlang", "kelvin"}
pi#87r#29"3.14159265358979323846264338327950288"
c#87r#29"2.99792458e8 m/sec"
g#87r#29"9.80665 m/sec2"
au#87r#29"1.49599e11 m"
mole#87r#29"6.022045e23"
e#87r#29"1.6020e-19 coul"
abcoulomb#87r#29"10 coul"
force#87r#29"g"
slug#87r#29"lb g sec2/ft"
mercury#87r#29"1.3157895 atm/m"
hg#87r#29"mercury"
torr#87r#29"mm hg"
%#87r#29"1|100"
percent#87r#29"%"
cg#87r#29"centigram"
atmosphere#87r#29"1.01325 bar"
atm#87r#29"atmosphere"
psi#87r#29"lb g/in2"
bar#87r#29"1e6 dyne/cm2"
chemamu#87r#29"1.66024e-24 g"
physamu#87r#29"1.65979e-24 g"
amu#87r#29"chemamu"
chemdalton#87r#29"chemamu"
dalton#87r#29"chemamu"
physdalton#87r#29"physamu"
dozen#87r#29"12"
bakersdozen#87r#29"13"
quire#87r#29"25"
ream#87r#29"500"
gross#87r#29"144"
hertz#87r#29"1/sec"
cps#87r#29"hertz"
hz#87r#29"hertz"
khz#87r#29"kilohz"
mhz#87r#29"megahz"
rutherford#87r#29"1e6/sec"
degree#87r#29"1|180 pi radian"
circle#87r#29"2 pi radian"
turn#87r#29"2 pi radian"
revolution#87r#29"360 degrees"
rpm#87r#29"revolution/minute"
grade#87r#29"1|400 circle"
grad#87r#29"1|400 circle"
sign#87r#29"1|12 circle"
arcdeg#87r#29"1 degree"
arcmin#87r#29"1|60 arcdeg"
arcsec#87r#29"1|60 arcmin"
karat#87r#29"1|24"
proof#87r#29"1|200"
mpg#87r#29"mile/gal"
curie#87r#29"3.7e10/sec"
stoke#87r#29"1 cm2/sec"
steradian#87r#29"radian radian"
sr#87r#29"steradian"
sphere#87r#29"4 pi steradian"
ps#87r#29"picosec"
us#87r#29"microsec"
ns#87r#29"nanosec"
ms#87r#29"millisec"
sec#87r#29"second"
minute#87r#29"60 sec"
min#87r#29"minute"
hour#87r#29"60 min"
hr#87r#29"hour"
day#87r#29"24 hr"
week#87r#29"7 day"
quadrant#87r#29"5400 minute"
fortnight#87r#29"14 day"
year#87r#29"365.24219879 day"
yr#87r#29"year"
month#87r#29"1|12 year"
mo#87r#29"month"
decade#87r#29"10 year"
century#87r#29"100 year"
millenium#87r#29"1000 year"
gm#87r#29"gram"
myriagram#87r#29"10 kg"
mg#87r#29"milligram"
metricton#87r#29"1000 kg"
gamma#87r#29"1e-6 g"
metriccarat#87r#29"200 mg"
quintal#87r#29"100 kg"
lb#87r#29"0.45359237 kg"
pound#87r#29"lb"
lbf#87r#29"lb g"
cental#87r#29"100 lb"
stone#87r#29"14 lb"
ounce#87r#29"1|16 lb"
oz#87r#29"ounce"
avdram#87r#29"1|16 oz"
usdram#87r#29"1|8 oz"
dram#87r#29"avdram"
dr#87r#29"dram"
grain#87r#29"1|7000 lb"
gr#87r#29"grain"
shortton#87r#29"2000 lb"
ton#87r#29"shortton"
longquarter#87r#29"28 lb"
shortquarter#87r#29"500 lb"
longton#87r#29"2240 lb"
longhundredweight#87r#29"112 lb"
shorthundredweight#87r#29"100 lb"
wey#87r#29"252 lb"
carat#87r#29"205.3 mg"
scruple#87r#29"20 grain"
pennyweight#87r#29"24 grain"
apdram#87r#29"60 grain"
apounce#87r#29"480 grain"
appound#87r#29"5760 grain"
cm#87r#29"centimeter"
mm#87r#29"millimeter"
km#87r#29"kilometer"
parsec#87r#29"au radian/arcsec"
pc#87r#29"parsec"
nm#87r#29"nanometer"
micron#87r#29"1e-6 meter"
angstrom#87r#29"1e-8 meter"
fermi#87r#29"1e-13 cm"
point#87r#29"1|72.27 in"
pica#87r#29"0.166044 inch"
caliber#87r#29"0.01 in"
barleycorn#87r#29"1|3 in"
inch#87r#29"2.54 cm"
in#87r#29"inch"
mil#87r#29"0.001 in"
palm#87r#29"3 in"
hand#87r#29"4 in"
span#87r#29"9 in"
foot#87r#29"12 in"
feet#87r#29"foot"
ft#87r#29"foot"
cubit#87r#29"18 in"
pace#87r#29"30 inch"
yard#87r#29"3 ft"
yd#87r#29"yard"
fathom#87r#29"6 ft"
rod#87r#29"16.5 ft"
rd#87r#29"rod"
rope#87r#29"20 ft"
ell#87r#29"45 in"
skein#87r#29"360 feet"
cable#87r#29"720 ft"
furlong#87r#29"660 ft"
nmile#87r#29"1852 m"
nautmile#87r#29"nmile"
bolt#87r#29"120 feet"
mile#87r#29"5280 feet"
mi#87r#29"mile"
league#87r#29"3 mi"
nautleague#87r#29"3 nmile"
lightyear#87r#29"c yr"
engineerschain#87r#29"100 ft"
engineerslink#87r#29"0.01 engineerschain"
gunterchain#87r#29"66 ft"
gunterlink#87r#29"0.01 gunterchain"
ramdenchain#87r#29"100 ft"
ramdenlink#87r#29"0.01 ramdenchain"
acre#87r#29"43560 ft2"
rood#87r#29"0.25 acre"
are#87r#29"100 m2"
centare#87r#29"0.01 are"
hectare#87r#29"100 are"
barn#87r#29"1e-24 cm2"
section#87r#29"mi2"
township#87r#29"36 mi2"
cc#87r#29"cm3"
liter#87r#29"1000 cc"
l#87r#29"liter"
ml#87r#29"milliliter"
registerton#87r#29"100 ft3"
cord#87r#29"128 ft3"
boardfoot#87r#29"144 in3"
boardfeet#87r#29"boardfoot"
cordfoot#87r#29"0.125 cord"
cordfeet#87r#29"cordfoot"
last#87r#29"80 bu"
perch#87r#29"24.75 ft3"
stere#87r#29"m3"
cfs#87r#29"ft3/sec"
gallon#87r#29"231 in3"
imperial#87r#29"1.200949"
gal#87r#29"gallon"
quart#87r#29"1|4 gal"
qt#87r#29"quart"
magnum#87r#29"2 qt"
pint#87r#29"1|2 qt"
pt#87r#29"pint"
cup#87r#29"1|2 pt"
gill#87r#29"1|4 pt"
fifth#87r#29"1|5 gal"
firkin#87r#29"72 pint"
barrel#87r#29"31.5 gal"
petrbarrel#87r#29"42 gal"
hogshead#87r#29"63 gal"
hd#87r#29"hogshead"
tun#87r#29"252 gal"
kilderkin#87r#29"18 imperial gal"
noggin#87r#29"1 imperial gill"
floz#87r#29"1|4 gill"
fldr#87r#29"1|32 gill"
tablespoon#87r#29"4 fldr"
teaspoon#87r#29"1|3 tablespoon"
minim#87r#29"1|480 floz"
pk#87r#29"peck"
bushel#87r#29"8 dry gal"
dry#87r#29"268.8025 in3/gallon"
bu#87r#29"bushel"
british#87r#29"277.4193|231"
brbucket#87r#29"4 dry british gal"
brpeck#87r#29"2 dry british gal"
brbushel#87r#29"8 dry british gal"
brfirkin#87r#29"1.125 brbushel"
dryquartern#87r#29"2.272980 l"
liqquarten#87r#29"0.1420613 l"
butt#87r#29"126 gal"
bag#87r#29"3 brbushels"
brbarrel#87r#29"4.5 brbushels"
seam#87r#29"8 brbushels"
drachm#87r#29"3.551531 ml"
newton#87r#29"kg m/sec2"
pascal#87r#29"nt/m2"
nt#87r#29"newton"
joule#87r#29"nt m"
cal#87r#29"4.1868 joule"
gramcalorie#87r#29"cal"
calorie#87r#29"cal"
btu#87r#29"1054.35 joule"
frigorie#87r#29"kilocal"
kcal#87r#29"kilocal"
kcalorie#87r#29"kilocal"
langley#87r#29"cal/cm cm"
dyne#87r#29"erg/cm"
poundal#87r#29"ft lb/sec2"
pdl#87r#29"poundal"
erg#87r#29"1e-7 joule"
horsepower#87r#29"550 ft lb g/sec"
hp#87r#29"horsepower"
poise#87r#29"gram/cm sec"
reyn#87r#29"6.89476e-6 centipoise"
rhe#87r#29"1/poise"
coul#87r#29"coulomb"
statcoul#87r#29"3.335635e-10 coul"
ampere#87r#29"coul/sec"
abampere#87r#29"10 amp"
amp#87r#29"ampere"
watt#87r#29"joule/sec"
volt#87r#29"watt/amp"
v#87r#29"volt"
abvolt#87r#29"10 volt"
statvolt#87r#29"299.7930 volt"
ohm#87r#29"volt/amp"
abohm#87r#29"10 ohm"
mho#87r#29"1/ohm"
abmho#87r#29"10 mho"
siemens#87r#29"mho"
farad#87r#29"coul/volt"
abfarad#87r#29"10 farad"
statfarad#87r#29"1.112646e-12 farad"
pf#87r#29"picofarad"
abhenry#87r#29"10 henry"
henry#87r#29"sec2/farad"
stathenry#87r#29"8.987584e11 henry"
mh#87r#29"millihenry"
weber#87r#29"volt sec"
gauss#87r#29"maxwell/cm2"
electronvolt#87r#29"e volt"
ev#87r#29"e volt"
kev#87r#29"1e3 ev"
mev#87r#29"1e6 ev"
bev#87r#29"1e9 ev"
faraday#87r#29"9.648456e4coul"
gilbert#87r#29"0.7957747154 amp"
oersted#87r#29"1 gilbert / cm"
oe#87r#29"oersted"
cd#87r#29"candela"
lumen#87r#29"cd sr"
lux#87r#29"lumen/m2"
footcandle#87r#29"lumen/ft2"
footlambert#87r#29"cd/pi ft2"
lambert#87r#29"cd/pi cm2"
phot#87r#29"lumen/cm2"
stilb#87r#29"cd/cm2"
candle#87r#29"cd"
engcandle#87r#29"1.04 cd"
germancandle#87r#29"1.05 cd"
carcel#87r#29"9.61 cd"
hefnerunit#87r#29".92 cd"
candlepower#87r#29"12.566370 lumen"
baud#87r#29"bit/sec"
byte#87r#29"8 bit"
kb#87r#29"1024 byte"
mb#87r#29"1024 kb"
gb#87r#29"1024 mb"
word#87r#29"4 byte"
long#87r#29"4 word"
block#87r#29"512 byte"
mph#87r#29"mile/hr"
knot#87r#29"nmile/hr"
brknot#87r#29"6080 ft/hr"
mach#87r#29"331.45 m/sec"
energy#87r#29"c2"
ccs#87r#29"1|36 erlang"
peck#87r#29"2 dry gallon"
arpentcan#87r#29"27.52 mi"
apostilb#87r#29"cd/pi m2"
arpentlin#87r#29"191.835 ft"
astonomicalunit#87r#29"au"
atomicmassunit#87r#29"amu"
barie#87r#29"1e-1 nt/m2"
barye#87r#29"1e-1 nt/m2"
biot#87r#29"10 amp"
blondel#87r#29"cd/pi m2"
bottommeasure#87r#29"1|40 in"
refrigeration#87r#29"12000 but/ton hr"
centesimalminute#87r#29"1e-2 grade"
centesimalsecond#87r#29"1e-4 grade"
chain#87r#29"gunterchain"
circularinch#87r#29"1|4 pi in2"
circularmil#87r#29"1e-6|4 pi in2"
clusec#87r#29"1e-8 mm hg m3/s"
coomb#87r#29"4 bu"
crith#87r#29"9.06e-2 gram"
dioptre#87r#29"1/m"
displacementton#87r#29"35 ft3"
dopplezentner#87r#29"100 kg"
equivalentfootcandle#87r#29"lumen/pi ft2"
equivalentlux#87r#29"lumen/pi m2"
equivalentphot#87r#29"cd/pi cm2"
finger#87r#29"7|8 in"
franklin#87r#29"3.33564e-10 coul"
galileo#87r#29"1e-2 m/sec2"
geographicalmile#87r#29"nmile"
hefnercandle#87r#29"hefnerunit"
homestead#87r#29"1|4 mi2"
hyl#87r#29"gram force sec2/m"
imaginarycubicfoot#87r#29"1.4 ft3"
jeroboam#87r#29"4|5 gal"
line#87r#29"1|12 in"
link#87r#29"66|100 ft"
lusec#87r#29"1e-6 mm hg m3/s"
marineleague#87r#29"3nmile"
maxwell#87r#29"1e-8 weber"
mgd#87r#29"megagal/day"
minersinch#87r#29"1.5 ft3/min"
nail#87r#29"1|16 yd"
nit#87r#29"cd/m2"
nox#87r#29"1e-3 lux"
pieze#87r#29"1e3 nt/mt2"
pipe#87r#29"4 barrel"
pole#87r#29"rd"
quarter#87r#29"9 in"
quartersection#87r#29"1|4 mi2"
ra#87r#29"100 erg/gram"
rankine#87r#29"1.8 kelvin"
rehoboam#87r#29"156 floz"
rontgen#87r#29"2.58e-4 curie/kg"
rydberg#87r#29"1.36054e1 ev"
sabin#87r#29"1 ft2"
shippington#87r#29"40 ft3"
sigma#87r#29"microsec"
skot#87r#29"1e-3 apostilb"
spat#87r#29"sphere"
spindle#87r#29"14400 yd"
square#87r#29"100 ft2"
sthene#87r#29"1e3 nt"
tesla#87r#29"weber/m2"
thermie#87r#29"1e6 cal"
timberfoot#87r#29"ft3"
tonne#87r#29"1e6 gram"
water#87r#29"0.22491|2.54 kg/m2 sec2"
xunit#87r#29"1.00202e-13 m"
k#87r#29"1.38047e-16 erg/kelvin"
puncheon#87r#29"84 gal"
tnt#87r#29"4.6e6 m2/sec2"
basic_units_template#87r#29
list of 9{{"m", 0}, {"kg", 0}, {"s", 0}, {"coul", 0}, {"candela", 0}, {"radian", 0}, {"bit", 0}, {"erlang", 0}, {"kelvin", 0}}
meter#87r#29"m"
gram#87r#29"1|1000 kg"
second#87r#29"s"
inches#87r#29"inch"
sennight#87r#29"1 week"
help_msg#72rc#29
list of 20{"Utility verbs for converting from one unit of measure to another.", "", "Unusual conversions:", ":dd_to_dms => converts decimal (INT or FLOAT) Degrees into Degrees, Minutes,", " and Seconds. (Also works for decimal Hours.)", ":dms_to_dd => converts from Degrees (or Hours), Minutes, and Seconds to", " decimal Degrees (or Hours).", ":rect_to_polar => converts from cartesian (x,y) coordinates to polar.", ":polar_to_rect => converts from polar (r, theta) coordinates to cartesian.", ":F_to_C => converts from Fahrenheit to Celsius.", ":C_to_F => converts from Celsius to Fahrenheit.", ":C_to_K => converts from Celsius to Kelvin.", ":K_to_C => converts from Kelvin to Celsius.", ":F_to_R => converts from Fahrenheit to Rankine.", ":R_to_F => converts from Rankine to Fahrenheit.", "", "Standard conversions:", ":convert => takes two string inputs and attempts to determine the ", " multiplicative conversion factor. See the verb help for details", " and input format.\""}
aliases#1rc#29{"Conversion Utils"}
description#1rc#29"This is a utilities package for converting from one unit of measurement to another. Type 'help #770' for more details."
object_size#1r#29{30928, 1298433815}
hidden_verbs#1rc#29<clear>
phelp_msg#1rc#29<clear>
weight#1rc#29<clear>
owner_verbs#1rc#29<clear>
plural_name#1rc#29<clear>
client_image#1rc#29<clear>
listening#1rc#29<clear>

Ancestry

Ancestors (nearest first): #72 Generic Utilities Package#1 root

Children: none

Call graph

calls n87_6 #87:convert n87_7 #87:_do_convert n87_6->n87_7 n87_9 #87:_format_units n87_6->n87_9 n87_7->n87_7 n20_56 #20:first_word n87_7->n20_56 n87_14 #87:_do_value n87_7->n87_14 n20_24 #20:is_integer n87_7->n20_24 n20_70 #20:is_float n87_7->n20_70 n87_8 #87:_try_metric_prefix n87_7->n87_8 n20_38 #20:explode n87_14->n20_38

Source

dd_to_dms dh_to_hms

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":dd_to_dms(INT|FLOAT <degrees>) => LIST {INT <degrees>, INT <minutes>, FLOAT <seconds>}";
2"This verb converts decimal degrees to degrees, minutes, and seconds.";
3dd = tofloat(args[1]);
4s = (((dd - tofloat(d = toint(dd))) * 60.0) - tofloat(m = toint((dd - tofloat(d)) * 60.0))) * 60.0;
5return {d, m, s};

dms_to_dd hms_to_dh

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":dms_to_dd(INT|FLOAT <deg>, INT|FLOAT <min>, INT|FLOAT <sec>) => FLOAT <deg>";
2"This verb converts degrees/minutes/seconds to decimal degrees.";
3{d, m, s} = args[1..3];
4d = tofloat(d);
5m = tofloat(m);
6s = tofloat(s);
7return (d + (m / 60.0)) + (s / 3600.0);

rect_to_polar

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":rect_to_polar(INT|FLOAT <x>, INT|FLOAT <y>) => FLOAT <radius>, FLOAT <angle>.";
2"This verb converts from rectangular (x,y) coordinates to polar (r, theta) coordinates.";
3{x, y} = args[1..2];
4x = tofloat(x);
5y = tofloat(y);
6return {sqrt((x * x) + (x * x)), `atan(y, x) ! E_INVARG => 0.0'};

polar_to_rect

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":polar_to_rect(INT|FLOAT <radius>, INT|FLOAT <angle>) => FLOAT <x>, FLOAT <y>";
2"This verb converts from polar (radius, angle) coordinates to rectangulat (x,y) coordinates.";
3{r, a} = args[1..2];
4r = tofloat(r);
5a = tofloat(a);
6return {(r = r / (1.0 + (z2 = (z = tan(a / 2.0)) * z))) * (1.0 - z2), (r * 2.0) * z};

F_to_C degF_to_degC

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":F_to_C(INT|FLOAT <Fahrenheit>) => FLOAT <Celsius>";
2"This verb converts Fahrenheit degrees to Celsius degrees.";
3return (tofloat(args[1]) - 32.0) / 1.8;

C_to_F degC_to_degF

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":C_to_F(INT|FLOAT <Celsius>) => FLOAT <Fahrenheit>";
2"This verb converts Celsius degrees to Fahrenheit degrees.";
3return (tofloat(args[1]) * 1.8) + 32.0;

convert

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":convert(STR <units>, STR <units>) => FLOAT conversion factor | LIST errors.";
2"This verb attempts to compute the conversion factor between two sets of units. If the two inputs are of the same type (two speeds, two lengths, etc.), the value is returned. If the two inputs are not of the same type, a LIST is returned as follows: {1, {FLOAT <value>, STR <units>}. {FLOAT <value>, STR <units>}}. The 1 indicates that the two inputs were correctly formed. <value> is the conversion factor of the input into the basic <units>. This error output is useful for determining the basic structure and value of an unknown unit of measure. If either of the inputs can not be broken down to known units, a LIST is returned as follows: {0, STR <bad input>}.";
3"";
4"The format of the input strings is fairly straight forward: any multiplicative combination of units, ending in an optional digit to represent that unit is raised to a power, the whole of which is preceeded by an initial value. Examples: \"100 kg m/sec2\", \"35 joules\", \"2000 furlongs/fortnight\"";
5"";
6"Some example uses:";
7";$convert_utils:convert(\"2000 furlongs/fortnight\", \"mph\")";
8"=> 0.744047619047619";
9";$convert_utils:convert(\"kilowatt hours\", \"joules\")";
10"=> 3600000.0";
11"";
12";$convert_utils:convert(\"furlongs\", \"mph\")";
13"=> {1, {201.168, \"m\"}, {044704, \"m / s\"}}";
14"";
15";$convert_utils:convert(\"junk\", \"meters\")";
16"=> {0, \"junk\"}";
17{havestr, wantstr} = args;
18have = this:_do_convert(havestr);
19want = this:_do_convert(wantstr);
20if ((have && want) && (have[2] == want[2]))
21return have[1] / want[1];
22elseif (have && want)
23return {1, {have[1], this:_format_units(@have[2])}, {want[1], this:_format_units(@want[2])}};
24else
25return {0, have ? wantstr | havestr};
26endif

_do_convert

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

Source

1"THIS VERB IS NOT INTENDED FOR USER USAGE.";
2":_do_convert is the workhorse of $convert_utils:convert and is based loosely upon the 'units' Perl script the ships with BSD Unix.";
3"Essentially, it breaks the input up into values and units, attempts to break each unit down into elementary (basic) units, modifies the value as it goes, until it has no more input or can not convert a unit into a basic unit.";
4instr = args[1];
5units = this.basic_units_template;
6value = 1.0;
7top = 1;
8"Ensure that the division mark is a spearate word.";
9instr = $string_utils:substitute(instr, {{"/", " / "}});
10while (instr)
11"Grab the next word to process";
12{first, instr} = $string_utils:first_word(instr);
13if (first == "/")
14"Now we're working with values under the division mark - units with negative exponents.";
15top = 1 - top;
16continue;
17elseif (match(first, "|"))
18"The word was a value expressed as a ratio. Compute the ratio and adjust the value accordingly.";
19value = this:_do_value(first, value, top);
20continue;
21elseif ($string_utils:is_integer(first) || $string_utils:is_float(first))
22"The word was a value. Adjust the accumulated value accordingly.";
23value = top ? value * tofloat(first) | (value / tofloat(first));
24continue;
25elseif (match(first, "[0-9]$"))
26"The word ends with a digit, but isn't a value. It must be a powered unit. Expand it: cm3 => cm cm cm";
27subs = match(first, "%([a-zA-Z]+%)%([0-9]+%)");
28first = substitute("%1", subs);
29power = toint(substitute("%2", subs));
30while (power > 0)
31instr = (first + " ") + instr;
32power = power - 1;
33endwhile
34continue;
35else
36"Check to see if the word starts with one or more metric prefix and attempt to evaluate the prefix.";
37{first, value, top} = this:_try_metric_prefix(first, value, top);
38"Check to see if we have a basic unit. If so, adjust the apropriate unit count.";
39if (index = first in this.basic_units)
40units[index][2] = top ? units[index][2] + 1 | (units[index][2] - 1);
41continue;
42elseif (prop = `this.(first) ! E_PROPNF => 0')
43"Check to see if this is a known unit. If so, convert it and adjust the value and units.";
44result = this:_do_convert(prop);
45value = top ? value * result[1] | (value / result[1]);
46for i in [1..length(units)]
47units[i][2] = top ? units[i][2] + result[2][i][2] | (units[i][2] - result[2][i][2]);
48endfor
49continue;
50elseif (first[$] == "s")
51"Check to see if this is a normal 's'-ending plural, and try to do the above checks again.";
52temp = first[1..$ - 1];
53if (index = temp in this.basic_units)
54units[index][2] = top ? units[index][2] + 1 | (units[index][2] - 1);
55continue;
56elseif (prop = `this.(temp) ! E_PROPNF => 0')
57result = this:_do_convert(prop);
58value = top ? value * result[1] | (value / result[1]);
59for i in [1..length(units)]
60units[i][2] = top ? units[i][2] + result[2][i][2] | (units[i][2] - result[2][i][2]);
61endfor
62continue;
63endif
64endif
65"We were unable to find any conversion for the current word, so halt all operation and return 0.";
66return 0;
67endif
68endwhile
69"We were able to successfully convert each part of the input. Return the equivalent value and units.";
70return {value, units};

_try_metric_prefix

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

Source

1"THIS VERB IS NOT INTENDED FOR USER USAGE.";
2":_try_metric_prefix runs through the metrix multipliers and tries to match them against the beginning of the input string. If successful, the given value is adjusted appropritately, and the input string is modified. The verb loops until there are no more prefix matches. (Hence, \"kilodecameter\" can be matched with only one verb call.";
3"If anyone knows of other possibilities here, please let me know.";
4{first, value, top} = args;
5while (1)
6if (subs = match(first, "^yocto%(.*%)"))
7first = substitute("%1", subs);
8value = top ? value / 1e+24 | (value * 1e+24);
9continue;
10endif
11if (subs = match(first, "^zepto%(.*%)"))
12first = substitute("%1", subs);
13value = top ? value / 1e+21 | (value * 1e+21);
14continue;
15endif
16if (subs = match(first, "^atto%(.*%)"))
17first = substitute("%1", subs);
18value = top ? value / 1e+18 | (value * 1e+18);
19continue;
20endif
21if (subs = match(first, "^femto%(.*%)"))
22first = substitute("%1", subs);
23value = top ? value / 1e+15 | (value * 1e+15);
24continue;
25endif
26if (subs = match(first, "^pico%(.*%)"))
27first = substitute("%1", subs);
28value = top ? value / 1000000000000.0 | (value * 1000000000000.0);
29continue;
30endif
31if (subs = match(first, "^nano%(.*%)"))
32first = substitute("%1", subs);
33value = top ? value / 1000000000.0 | (value * 1000000000.0);
34continue;
35endif
36if (match(first, "^micron"))
37break;
38endif
39if (subs = match(first, "^micro%(.*%)"))
40first = substitute("%1", subs);
41value = top ? value / 1000000.0 | (value * 1000000.0);
42continue;
43endif
44if (subs = match(first, "^milli%(.*%)"))
45first = substitute("%1", subs);
46value = top ? value / 1000.0 | (value * 1000.0);
47continue;
48endif
49if (subs = match(first, "^centi%(.*%)"))
50first = substitute("%1", subs);
51value = top ? value / 100.0 | (value * 100.0);
52continue;
53endif
54if (subs = match(first, "^deci%(.*%)"))
55first = substitute("%1", subs);
56value = top ? value / 10.0 | (value * 10.0);
57continue;
58endif
59if (subs = match(first, "^%(deca%|deka%)%(.*%)"))
60first = substitute("%2", subs);
61value = (!top) ? value / 10.0 | (value * 10.0);
62continue;
63endif
64if (subs = match(first, "^hecto%(.*%)"))
65first = substitute("%1", subs);
66value = (!top) ? value / 100.0 | (value * 100.0);
67continue;
68endif
69if (subs = match(first, "^kilo%(.*%)"))
70first = substitute("%1", subs);
71value = (!top) ? value / 1000.0 | (value * 1000.0);
72continue;
73endif
74if (subs = match(first, "^mega%(.*%)"))
75first = substitute("%1", subs);
76value = (!top) ? value / 1000000.0 | (value * 1000000.0);
77continue;
78endif
79if (subs = match(first, "^giga%(.*%)"))
80first = substitute("%1", subs);
81value = (!top) ? value / 1000000000.0 | (value * 1000000000.0);
82continue;
83endif
84if (subs = match(first, "^tera%(.*%)"))
85first = substitute("%1", subs);
86value = (!top) ? value / 1000000000000.0 | (value * 1000000000000.0);
87continue;
88endif
89if (subs = match(first, "^peta%(.*%)"))
90first = substitute("%1", subs);
91value = (!top) ? value / 1e+15 | (value * 1e+15);
92continue;
93endif
94if (subs = match(first, "^exa%(.*%)"))
95first = substitute("%1", subs);
96value = (!top) ? value / 1e+18 | (value * 1e+18);
97continue;
98endif
99if (subs = match(first, "^zetta%(.*%)"))
100first = substitute("%1", subs);
101value = (!top) ? value / 1e+21 | (value * 1e+21);
102continue;
103endif
104if (subs = match(first, "^yotta%(.*%)"))
105first = substitute("%1", subs);
106value = (!top) ? value / 1e+24 | (value * 1e+24);
107continue;
108endif
109break;
110endwhile
111return {first, value, top};

_format_units

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

Source

1"THIS VERB IS NOT INTENDED FOR USER USAGE.";
2":_format_units takes the associative list of units and powers and construct a more user friendly string.";
3top = bottom = "";
4for pair in (args)
5if (pair[2] > 0)
6top = tostr(top, " ", pair[1], (pair[2] > 1) ? pair[2] | "");
7elseif (pair[2] < 0)
8bottom = tostr(bottom, " ", pair[1], (pair[2] < -1) ? -pair[2] | "");
9endif
10endfor
11if (bottom)
12return ((top + " /") + bottom)[2..$];
13else
14return top[2..$];
15endif

K_to_C degK_to_degC

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":K_to_C (INT|FLOAT <Kelvin>) => FLOAT <Celcius>";
2"This verb converts Kelvin degrees to Celcius degrees.";
3return tofloat(args[1]) - 273.0;

C_to_K degC_to_degK

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":C_to_K (INT|FLOAT <Celcius>) => FLOAT <Kelvin>";
2"This verb converts Celcius degrees to Kelvin degrees.";
3return tofloat(args[1]) + 273.0;

F_to_R degF_to_degR

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":F_to_R (INT|FLOAT <Fahrenheit>) => FLOAT <Rankine>";
2"This verb converts Fahrenheit degrees to Rankine degrees.";
3return tofloat(args[1]) + 491.4;

R_to_F degR_to_degF

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

none

Source

1":R_to_F (INT|FLOAT <Rankine>) => FLOAT <Fahrenheit>";
2"This verb converts Rankine degrees to Fahrenheit degrees.";
3return tofloat(args[1]) - 491.4;

_do_value

Spec this none thisFlags rxdOwner #29Definer #87

Referenced by

Source

1"THIS VERB IS NOT INTENDED FOR USER USAGE.";
2":_do_value takes a string of the form <number>|<number>, interprets it as a ratio, and applies that ratio to the incoming 'value' accordingly with the 'top' input, and returns it back to the calling verb.";
3{first, value, top} = args;
4{numer, denom} = $string_utils:explode(first, "|");
5return top ? (value * tofloat(numer)) / tofloat(denom) | ((value * tofloat(denom)) / tofloat(numer));