[ unit ]

“msharpmath”, The Simple is the Best

[100] 031 Tutorial units             [units]

//————————————————————————————————————
// Why m#math in unit conversion
//————————————————————————————————————
Consider multiple operations as in PV/T where

pressure    : P = 300 torr = 39.9967 kPa
volume      : V = 3.2 barrel = 0.5088 m^3
temperature : T = 30 C = 303.15 K

With these mixed units,

#> 300*_torr * 3.2*_bbl / 30.c ;      // using unit  constants approach
#> 300   .torr *  3.2   .bbl / 30.c ;      // using dot . conversion approach
ans =      0.06712956
ans =      0.06712956

become exactly the same as

#> 39.9967 * 0.5088 / 303.15 ;       //   [kPa.m^3/K]
ans =     0.067129543

In particular, temperature conversion does not have unit constants since conversion is not based on proportionality alone.   In many calculations involving unit conversions, all units are automatically converted into the reference units described below.   This would help scientists and engineers to avoid headache in unit conversions.

//————————————————————————————————————
// Reference Units
//————————————————————————————————————
For convenience, reference units are fixed in m#math.

[kg]              mass, weight
[m]               length
[m^2]          area
[m^3]          volume
[m/s]            speed
[s]                  time
[K]                 temperature (Kelvin)
[kN]              force
[kPa]             pressure
[kJ]               energy
[kW]             power
[kN.m]         torque
[kg/m^3]    density
[m/s^2]       accceleration

//————————————————————————————————————
//  unit constants approach
//————————————————————————————————————
The unit constants are listed in ‘constants’ page.  For example,

_ft    = 0.3048 meter = 1 feet
_cm = 0.01 meter       = 1 centi-meter

are declared and can be used to convert 3 ft into cm as follows.

3 * _ft / _cm = 3 * (0.3048) / (0.01) = 91.44

Also, derived units such as pound per barrel (lb/bbl) can be converted into kilogram per deciliter

#> 15 * (_lb/_bbl) / (_kg/_dL) ;
ans = 0.0042791733  [kg/dL]  =  15 [lb/bbl]

The unit constants approach is more oriented for scientific calculations. For use in common life, the dot . conversion approach would be more convenient.

//————————————————————————————————————
//  dot .  conversion approach
//————————————————————————————————————
The dot  .  conversion approach converts a corresponding unit into the reference unit. The converted value is used for mathematical operations. For example,

#> 2.ft + 1.ft ;    // the final result is always in the reference unit [m]
ans =          0.9144

Users are responsible for the unit consistency in mathematical operations.

#> 1.ft * 2.kg ;       // ‘ length * mass’  occurs when a wire weighs 2kg per feet.
#> 1.ft + 2.kg ;      // ‘ length + mass’  is absurd !!!   no meaning at all
ans =     2.3048
ans =     2.3048

m#math do not check if the unit usage is physically correct. The dot conversion approach becomes very complicated with mixed derived units. In such cases, the unit constants approach would be helpful.

//————————————————————————————————————
//  Single dot for all-in-one conversions
//————————————————————————————————————
A single ‘dot’ operation followed by a semi-colon ‘;’ results in all-in-one conversion. The final return value is in the reference unit.

#> 77 .f ;      // temperature
25 [C]
77 F
536.67 R
298.15 K

ans =          298.15   // in the reference unit [K]

#> 3 .ft ;                          // single ‘dot’ for all-in-one conversion
0.9144 m (meter)        // the first entry is the reference unit
0.0009144 km
91.44 cm
914.4 mm
914400 micro m
9.144e+008 nm
9.144e+009 angstrom

36 in (inch) ,  3 ft 0 in
3 ft (feet)
1 yd (yard)
0.000568182 mi (mile)
0.000493737 nmi (nautical mile)

ans =          0.9144          // in the reference unit [m]

#> 25 .psi ;           // pressure
172.369 kPa
0.172369 MPa
172369 Pa
0.000172369 GPa
1723.69 hPa
1723.69 mb
1.72369 bar
1292.87 mmHg (torr)
129.383 cmHg
17577.2 mmAq
1757.72 cmAq
1.75767 atmtec, kgf/cm^2
1.70115 atm

25 psi, lbf/in^2
3600 psf, lbf/ft^2
0.025 ksi, 1000 lbf/in^2
3.6 ksf, 1000 lbf/ft^2
691.997 inAq
50.9005 inHg

ans =       172.36893    // in the reference unit [kPa]

#> 25.4 .bbl ;   // barrel, volume             // note that 25.4 has a dot inside.
4.0386 m^3
4038.6 L (liter)
40386 dL
4.0386e+006 cc (mL, cm^3)
4.0386e+009 mm^3
4.0386e-009 km^3

246452 in^3
142.622 ft^3
5.28198 yd^3
9.68907e-010 mi^3
819368 tsp (teaspoon)
273123 tbsp (tablespoon)
136561 floz (fluid ounce)
34140.3 gill
17070.2 cup
8535.08 pt (pint)
4267.54 qt (quart)
1066.89 gal (gallon)
25.4 bbl (barrel)

ans =          4.0386

//————————————————————————————————————
//   length [m]
//————————————————————————————————————
_m       = 1 .m            1 [m], meter
_A        = 1 .A             10^-10 [m], angstrom
_nm    = 1 .nm          10^-9 [m], nanometer
_mum = 1 .mum      10^-6 [m], micron
_mm   = 1 .mm         0.001 [m], millimeter
_cm     = 1 .cm          0.01 [m], centimeter
_km     = 1 .km         1000 [m], kilometer
_in       = 1 .in            0.0254 [m], inch
_ft       = 1 .ft              0.3048 [m], feet
_yd     = 1 .yd             0.9144 [m] = 3 [ft], yard
_mi     = 1 .mi            1609.344 [m] = 1760 [yd], mile
_nmi   = 1 .nmi         1852 [m], nautical mile
_au     = 1 .au            1.496 x 10^11 [m], astronomical unit
_ly      = 1 .ly             9.4607 x 10^15 [m], light year
_pc     = 1 .pc            3.0857 x 10^16 [m], parsec

Two units, foot and inch, are expressed by prime (‘) and are converted into meter [m] if not specified explicitly.

1 foot = 1′ = 0.3048 m
1 inch = 1” = 0.0254 m

#> 5’3” ;                       // 5 feet 3 inches in all other length units
1.6002 m (meter)
0.0016002 km
160.02 cm
1600.2 mm
1.6002e+006 micro m
1.6002e+009 nm
1.6002e+010 angstrom

63 in (inch) ,  5 ft 3 in
5.25 ft (feet)
1.75 yd (yard)
0.000994318 mi (mile)
0.000864039 nmi (nautical mile)

ans =          1.6002

//————————————————————————————————————
//  area [m^2]
//————————————————————————————————————
_m2          = 1 .m2            1 [m^2], square meter
_km2       = 1 .km2         10^6 [m^2], square kilometer
_cm2       = 1 .cm2         10^-4 [m^2], square centimeter
_mm2      = 1 .mm2        10^-6 [m^2], square millimeter
_in2         = 1 .in2            6.4516 x 10^-4 [m^2], square inch
_ft2          = 1 .ft2             0.09290304 [m^2], square feet
_yd2        = 1 .yd2            0.83612736 [m^2], square yard
_mi2        = 1 .mi2           2589988.110336 [m^2], square mile
_ac           = 1 .ac              4046.8564224 [m^2] = 43560 [ft^2], acre   // _acre
_ha          = 1 .ha             10000 [m^2], hectare
_py          = 1 .py             3.30579 [m^2], pyung

//————————————————————————————————————
//  volume [m^3]
//————————————————————————————————————
_m3        = 1 .m3                                     1 [m^3], cubic meter
_km3     = 1 .km3                                   10^9 [m^3], cubic kilometer
_L          = 1 .L                                         0.001 [m^3], liter
_dL        = 1 .dL                                       0.0001 [m^3], deciliter
_cm3      = 1 .cm3                                   10^-6 [m^3], milliliter or cubic centimeter
_cc         = 1 .cc                                        10^-6 [m^3], milliliter or cubic centimeter
_mL       = 1 .mL                                     10^-6 [m^3], milliliter or cubic centimeter
_mm3    = 1 .mm3                                  10^-9 [m^3], cubic millimeter
_in3        = 1 .in3                                     16.387064 x 10^-6 [m^3], cubic inch
_ft3        = 1 .ft3                                      0.028316846592 [m^3], cubic feet
_yd3      = 1 .yd3                                    0.764554857984 [m^3], cubic yard
_mi3      = 1 .mi3                                    4.16818182544058 x 10^9 [m^3], cubic mile

_bbl       = 1 .bbl                                     0.159 [m^3], barrel (petroleum)  // _barrel

_tsp       = 1 .tsp                                     4.92892 x 10^-6 [m^3], teaspoon(US)
_tbsp     = 1 .tbsp                                  14.78676 x 10^-6 [m^3], tablespoon(US)
_floz       = 1 .floz                                    29.5735 x 10^-6 [m^3], ounce(US)
_gill        = 1 .gill                                     118.2941 x 10^-6 [m^3], gill(US)
_cup       = 1 .cup                                    236.588 x 10^-6 [m^3], cup(US)
_pt         = 1 .pt                                       473.1765 x 10^-6 [m^3], pint(US)  // _pint
_qt         = 1 .qt                                        946.35296 x 10^-6 [m^3], quart(US)  // _quart
_gal        = 1 .gal                                      0.00378541 [m^3], gallon(US)  // _gallon

_Tsp       = 1 .Tsp                                     3.5516328125 x 10^-6 [m^3], teaspoon(UK)
_Tbsp     = 1 .Tbsp                                  14.20653125 x 10^-6 [m^3], tablespoon(UK)
_Floz       = 1 .Floz                                    28.4130625 x 10^-6 [m^3], ounce(UK)
_Gill        = 1 .Gill                                     142.0653125 x 10^-6 [m^3], gill(UK)
_Cup       = 1 .Cup                                    284.130625 x 10^-6 [m^3], cup(UK)
_Pt         = 1 .Pt                                       568.26125 x 10^-6 [m^3], pint(UK)  // _Pint
_Qt         = 1 .Qt                                        1136.5225 x 10^-6 [m^3], quart(UK)  // _Quart
_Gal       = 1 .Gal                                     0.00454609 [m^3], gallon(UK)  // _Gallon

%>===================================================
US units
1 gal(US) = 3.78541 L
= 4 quart (1 quart = 2 pint)
= 8 pint (1 pint = 2 cup)
= 16 cup (1 cup = 2 gill)
= 32 gill (1 gill = 4 ounce)
= 128 ounce (1 ounce = 2 tablespoon)
= 256 tablespoon ( 1tbsp = 3 teaspoon )
= 768 teaspoon

UK units
1 gal(UK) = 4.54609 L
= 4 quart (1 quart = 2 pint)
= 8 pint (1 pint = 4 gill)
= 32 gill (1 gill = 5 ounce)
= 160 ounce (1 ounce = 2 tablespoon)
= 320 tablespoon ( 1tbsp = 4 teaspoon )
= 1280 teaspoon

//————————————————————————————————————
//  mass [kg]
//————————————————————————————————————
_kg      = 1 .kg                   1 [kg], kilogram
_mg     = 1 .mg                 10^-6 [kg], milligram
_gram = 1 .gram               0.001 [kg], gram
_ton     = 1 .ton                 1000 [kg], ton, metric ton-mass
_Ton   = 1 .Ton                907.1847 [kg], English ton-mass

_oz, _ozm = 1 .oz, 1 .ozm         0.0283495 [kg], ounce-mass
_lb, _lbm = 1 .lb, 1 .lbm           0.45359237 [kg], pound-mass
_slug = 1 .slug                            14.5939 [kg] = 32.174 [lbm], slug
_stone                                          6.3502932  [kg]
_gr   = 1 .gr                                  6.479891 x 10^-5 [kg], grain
_kt, _carat = 1 .kt                      205.2 x 10^-6 [kg], carat

//————————————————————————————————————
//  time [s]
//————————————————————————————————————
_s                     = 1 .s                          1  [s]   // second
_min               = 1 .min                    60  [s]  // minute
_hr, _hour     = 1 .hr, 1 .hour         3600  [s]
_day                = 1 .day                     86400  [s]
_week             = 1 .week                  604800  [s]
_ms                 = 1 .ms                      0.001  [s] // milli second
_mus               = 1 .mus                   1e-006  [s]  // micro second
_ns                   = 1 .ns                      1e-009  [s] // nano second
_yr                   = 1 .yr                       31536000  [s]  // non-leap year
_lyr                  = 1 .lyr                      31622400  [s] // leap year
_gyr                 = 1 .gyr                     31556952  [s] // gregorian year
_jyr                  = 1 .jyr                      31557600 [s] // julian year

//————————————————————————————————————
//  speed [m/s]
//————————————————————————————————————
_m/_s       = 1 .mps            1 [m/s], meter per second
_m/_min  = 1 .mpm           0.016666667 [m/s], meter per minute
_m/_hr     = 1 .mphr           0.0002777777778 [m/s], meter per hour

_kmph        = 1 .kmph           0.2777777778 [m/s], km per hour  //_km/_hr
_km/_min = 1 .kmpm          16.666667 [m/s], km per min
_km/_s      = 1 .kmps           1000 [m/s], km per s

_mph         = 1 .mph             0.44704 [m/s], mile per hour  // _mi/_hr
_mi/_min = 1 .mipm           26.8224 [m/s], mile per min
_mi/_s      = 1 .mips            1609.344 [m/s], mile per s

_yd/_hr    = 1 .ydph             0.000254 [m/s], yard/h
_yd/_min = 1 .ydpm           0.015424 [m/s], yard/min
_yd/_s      = 1 .ydps             0.9144 [m/s], yard/s

_ft/_hr     = 1 .ftph               0.0000846667 [m/s], ft/h
_ft/_min  = 1 .ftpm             0.00508 [m/s], ft/min
_ft/_s       = 1 .ftps               0.3048 [m/s], ft/s

_knot, _kn = 1 .kn              0.514444 [m/s], knot
_mach = 1 .ma                     320 [m/s], speed of sound (mach)
_c0                                         2.9979246 x 10^8  [m/s]  // speed of light

//————————————————————————————————————
//  temperature [K]
//————————————————————————————————————
For a number x, temperature conversion is treated below

(1) conversion into Kelvin ( c2k, f2k, r2k )

x [C] —> x + 273.15 [K]
x [F] —> (x + 459.67) / 1.8 [K]
x [R] —> x / 1.8 [K]

#> 25.c2k ;               ans =          298.15
#> 77.f2k ;                ans =          298.15
#> 540.r2k ;             ans =             300

(2) conversion into Celsius ( k2c, f2c, r2c )

x [K] —> x – 273.15 [C]
x [F] —> (x – 32) / 1.8 [C]
x [R] —> (x – 491.67) / 1.8 [C]

#> 300.k2c ;              ans =           26.85
#> 77.f2c ;                  ans =              25
#> 540.r2c ;               ans =           26.85

(3) conversion into Fahrenheit ( k2f, c2f, r2f )

x [K] —> 1.8 * x – 459.67 [F]
x [C] —> 1.8 * x + 32 [F]
x [R] —> x – 459.67 [F]

#> 300.k2f ;                  ans =           80.33
#> 25.c2f ;                     ans =              77
#> 540.r2f ;                   ans =           80.33

(4) conversion into Rankine ( k2r, c2r, f2r )

x [K] —> 1.8 * x [R]
x [C] —> 1.8 * x + 491.67 [R]
x [F] —> x + 459.67 [R]

#> 300.k2r ;                   ans =             540
#> 25.c2r ;                      ans =          536.67
#> 77.f2r ;                       ans =          536.67

//————————————————————————————————————
//  force [kN]
//————————————————————————————————————
_kN     = 1 .kN                    1 [kN] , kilo newton
_N       = 1 .N                      0.001 [kN],  newton
_MN   = 1 .MN                  1000 [kN], mega newton
_GN    = 1 .GN                    10^6 [kN],  giga newton
_dyne = 1 .dyne                 10^-8 [kN],  dyne  // _dyn
_kgf    = 1 .kgf                    9.80665 x 10^-3 [kN], kilogram-force
_ozf     = 1 .ozf                     0.278014 x 10^-3 [kN], ounce-force
_lbf     = 1 .lbf                     4.4482216 x 10^-3 [kN], pound-force
_kip    = 1 .kip                    4.4482216 [kN] = 1000 [lbf], kip
_tonf   = 1 .tonf                  9.80665 [kN], ton-force
_Tonf  = 1 .Tonf                 8.896443239 [kN], English ton-force
_pdl    = 1 .pdl                    0.138255 x 10^-3 [kN], poundal

//————————————————————————————————————
//  pressure [kPa]
//————————————————————————————————————
_kPa       = 1 .kPa                 1 [kPa], kilo Pascal
_Pa         = 1 .Pa                   0.001 [kPa], Pascal
_hPa       = 1 .hPa                 0.1 [kPa], hecto Pascal
_MPa     = 1 .MPa               1000 [kPa], mega Pascal
_GPa      = 1 .GPa                10^6 [kPa], giga Pascal
_bar       = 1 .bar                 100 [kPa], bar
_mb       = 1 .mb                 0.1 [kPa], millibar   // _mbar
_mmAq = 1 .mmAq           0.00980638 [kPa], mm of water
_cmAq   = 1 .cmAq             0.0980638 [kPa], cm of water
_inAq     = 1 .inAq               0.249089 [kPa], inch of water
_mmHg  = 1 .mmHg           0.133322368 [kPa], mm of mercury
_cmHg   = 1 .cmHg             1.3322368 [kPa], cm of mercury
_inHg     = 1 .inHg               3.386389 [kPa], inch of mercury
_torr      = 1 .torr                 0.133322368 [kPa], mmHg
_psi        = 1 .psi                   6.8947572695 [kPa], lbf/in^2
_psf        = 1 .psf                   0.04788027943 [kPa], lbf/ft^2
_ksi        = 1 .ksi                    6894.7572695 [kPa], kip/in^2
_ksf        = 1 .ksf                   47.88027943 [kPa], kip/ft^2
_atm      = 1 .atm                  101.32501 [kPa] = 760 [mmHg], atmosphere
_atmtec = 1 .atmtec            98.0665 [kPa], atm technical [kgf/cm^2]
_kgf/_cm2 = 1 .kgfpcm2         98.0665 [kPa], atm technical

//————————————————————————————————————
//  energy [kJ]
//————————————————————————————————————
_kJ       = 1 .kJ                     1 [kJ], kilo Joule
_J         = 1 .J                       0.001 [kJ], Joule
_MJ     = 1 .MJ                   1000 [kJ], mega Joule
_GJ      = 1 .GJ                    10^6 [kJ], giga Joule
_mJ     = 1 .mJ                    10^-6 [kJ], mill Joule
_erg    = 1 .erg                    10^-10 [kJ], erg
_cal     = 1 .cal                     0.0041868 [kJ], calorie
_kcal   = 1 .kcal                  4.1868 [kJ], kilo calorie
_Cal    = 1 .Cal                   4.1868 [kJ], kilo calorie
_BTU = 1 .BTU                 1.0550559 [kJ]
_Wh    = 1 .Wh                   3.6 [kJ], Watt-hour // _W*_hr
_kWh  = 1 .kWh               3600 [kJ], kiloWatt-hour // _kW*_hr
_hph  = 1 .hph                   2.6845195 x 10^3 [kJ], hoursepower-hour // _hp*_hr

_therm   = 1 .therm              0.1054804 x 10^6 [kJ], therm(US)
_Therm = 1 .Therm             0.10550559 x 10^6 [kJ], therm(Europe)

//————————————————————————————————————
//  power [kW]
//————————————————————————————————————
_kW    = 1 .kW                     1 [kW], kilo Watt
_W      = 1 .W                       0.001 [kW], Watt
_MW  = 1 .MW                    1000 [kW], mega Watt
_GW   = 1 .GW                     10^6 [kW], giga Watt
_mW  = 1 .mW                     10^-6 [kW], milli Watt

_hp     = 1 .hp                        0.74569987 [kW], horsepower(international)
_hpm = 1 .hpm                     0.73549875 [kW], horsepower(metric)
_bhp   = 1 .bhp                      9.810657 [kW], boiler hp

_cal/_hr    = 1 .calph                   1.1163 x 10^-6 [kW], calorie/h
_cal/_min = 1 .calpm                  0.06978 x 10^-3 [kW], calorie/min
_cal/_s      = 1 .calps                    0.0041868 [kW], calorie/s

_BTU/_hr    = 1 .BTUph                0.29307108 x 10^-3 [kW], BTU/h
_BTU/_min = 1 .BTUpm               17.584265 x 10^-3 [kW], BTU/min
_BTU/_s      = 1 .BTUps                 1.0550559 [kW], BTU/s

_ft*_lbf/_hr    = 1 .ftlbph               0.3766161 x 10^-6 [kW], ft.lbf/h
_ft*_lbf/_min = 1 .ftlbpm              0.022596965 x 10^-3 [kW], ft.lbf/min
_ft*_lbf/_s      = 1 .ftlbps                1.3558179 x 10^-3 [kW], ft.lbf/s

//————————————————————————————————————
//  torque [kN.m]
//————————————————————————————————————
_kN*_m =  1 .kNm                    1 [kN.m], kN.m
_N*_m    = 1 .Nm                       0.001 [kN.m], N.m
_N*_cm  = 1 .Ncm                     0.01 x 10^-3 [kN.m], N.cm

_lbf*_ft    = 1 .lbft                        1.3558179 x 10^-3 [kN.m], lbf.ft
_lbf*_in   = 1 .lbin                       0.11298482 x 10^-3 [kN.m], lbf.in
_ozf*_ft   = 1 .ozft                        0.084738667 x 10^-3 [kN.m], ozf.ft
_ozf*_in  = 1 .ozin                      7.06156 x 10^-6 [kN.m], ozf.in
_pdl*_ft  = 1 .pdlft                      0.042140124 x 10^-3 [kN.m], pdl.ft
_pdl*_in = 1 .pdlin                      3.511677 x 10^-6 [kN.m], pdl.in

//————————————————————————————————————
//  density [kg/m^3]
//————————————————————————————————————
_kg/_m3          = 1 .kgpm3                    1 [kg/m^3]  , kg per cubic meter
_gram/_L        = 1 .gpL                          1 [kg/m^3], gram per liter
_gram/_cm3    = 1 .gpcm3                     1000 [kg/m^3], gram per cm^3

_oz/_in3 = 1 .ozpin3                    1729.989044 [kg/m^3], ozm/in^3
_oz/_ft3 = 1 .ozpft3                     1.00115 [kg/m^3], ozm/ft^3

_lb/_in3 = 1 .lbpin3                     27679.905 [kg/m^3], lbm/in^3
_lb/_ft3 = 1 .lbpft3                      16.018463 [kg/m^3], lbm/ft^3

_slug/_in3 = 1 .slugpin3                 890574.42 [kg/m^3], slug/in^3
_slug/_ft3 = 1 .slugpft3                  515.378711 [kg/m^3], slug/ft^3

_oz/_gal = 1 .ozpgal                     7.4891491 [kg/m^3], ozm/gal(US)
_lb/_gal = 1 .lbpgal                      119.82648 [kg/m^3], lbm/gal(US)
_gr/_gal = 1 .grpgal                     0.017118069 [kg/m^3], grain/gal(US)

_oz/_Gal = 1 .ozpGal                    6.2360182 [kg/m^3], ozm/gal(UK)
_lb/_Gal = 1 .lbpGal                    99.776372 [kg/m^3], lbm/gal(UK)
_gr/_Gal = 1 .grpGal                    0.014253767 [kg/m^3], grain/gal(UK)

//————————————————————————————————————
//  acceleration [m/s^2]
//————————————————————————————————————
_m/_s^2          = 1 .mps2                      1 [m/s^2]  , meter per square second
_cm/_s^2        = 1 .cmps2                    0.01 [m/s^2]
_mm/_s^2      = 1 .mmps2                  0.001 [m/s^2]
_km/(_hr*_s) = 1 .kmphs                    0.27777777777 [m/s^2]

_ft/_s^2           = 1 .ftps2                        0.3048 [m/s^2]
_in/_s^2          = 1 .inps2                        0.0254 [m/s^2]
_ft/(_hr*_s)    = 1 .ftphs                         8.4666667 x 10^-5 [m/s^2]
_in/(_hr*_s)   = 1 .inphs                        7.0555556 x 10^-6 [m/s^2]
_mi/(_hr*_s)  = 1 .mphs                       0.44704 [m/s^2]

_g                                 9.80665 [m/s^2]
_gc                                32.174,  British unit coefficient

Comments are closed.