Units
Dewy was designed from day 1 to include physical units such as kilogram, meter, second.
A Simple Example
Using units is quite straightforward, as they are just another expression. Juxtaposing a unit with a number will multiply the number by the unit, and you can use this to build up more complex expressions.
The energy
variable now contains a value of 9000 joules
. For more complex unit expressions, sometimes it is necessary to use parentheses to group terms together. In general it is good style to do so, except for the simplest unit expressions. See Operator Precedence.
Here are several more examples of unit expressions:
SI Prefixes
Note: SI prefixes only work for SI base and derived units (and a few exceptions noted below). Also the abbreviated forms of prefixes may only be combined with abbreviated units, and written out prefixes may only be combined with written out units. E.g.
kilograms
andkg
are valid, butkgrams
andkilog
are invalid.
Prefix | Abbrev. | Scale |
---|---|---|
yotta | Y | 10^24 |
zetta | Z | 10^21 |
exa | E | 10^18 |
peta | P | 10^15 |
tera | T | 10^12 |
giga | G | 10^9 |
mega | M | 10^6 |
kilo | k | 10^3 |
hecto | h | 10^2 |
deca | da | 10^1 |
deci | d | 10^−1 |
centi | c | 10^−2 |
milli | m | 10^−3 |
micro | μ /u | 10^−6 |
nano | n | 10^−9 |
pico | p | 10^−12 |
femto | f | 10^−15 |
atto | a | 10^−18 |
zepto | z | 10^−21 |
yocto | y | 10^−24 |
Non-SI units that may receive SI prefixes:
psi
(e.g.kpsi
=1000(psi)
)torr
(e.g.mTorr
=0.001(torr)
)bar
(e.g.mbar
=0.001(bar)
)eV
(e.g.keV
=1000(eV)
)cal
(e.g.kcal
=1000(cal)
)- (TODO: probably more)
Binary Prefixes
Note: These prefixes are exclusively for use with units of information (e.g.
bit
/byte
)
Prefix | Abbrev. | Scale |
---|---|---|
kibi | Ki | 2^10 |
mebi | Mi | 2^20 |
gibi | Gi | 2^30 |
tebi | Ti | 2^40 |
pebi | Pi | 2^50 |
exbi | Ei | 2^60 |
zebi | Zi | 2^70 |
yobi | Yi | 2^80 |
Full List of Units
(TODO->maybe like solidworks, allow user to set unit system, e.g. meters-kilograms-seconds, centimeters-grams-seconds, etc. See: https://en.wikipedia.org/wiki/MKS_system_of_units https://en.wikipedia.org/wiki/Metre%E2%80%93tonne%E2%80%93second_system_of_units https://en.wikipedia.org/wiki/Foot%E2%80%93pound%E2%80%93second_system https://en.wikipedia.org/wiki/Centimetre%E2%80%93gram%E2%80%93second_system_of_units )
Base Units
Note: abbreviated units and prefixes are case sensitive, while fully written out units and prefixes are case insensitive
Quantity | Symbol | Abbrev. Units | Full Units |
---|---|---|---|
Mass* | [M] | g k lbm - | gram /grams kilo /kilos pound-mass /pounds-mass slug /slugs |
Length | [L] | m - ft yd mi - AU - - | meter /meters /metre /metres inch /inches foot /feet yard /yards mile /miles nautical_mile /nautical_miles astronomical_unit /astronomical_units light_year /light_years parsec /parsecs |
Time | [T] | s - - - - - - - - - | second /seconds minute /minutes hour /hours day /days week /weeks month /months year /years decade /decades century /centuries millennium /millennia |
Electric Current | [I] | A | amp /amps /ampere /amperes |
Thermodynamic Temperature | [Θ] | K °R /°Ra °C °F | kelvin rankine /degrees_rankine celsius /degrees_celsius fahrenheit /degrees_fahrenheit |
Amount of Substance | [N] | mol | mole /moles |
Luminous Intensity | [J] | cd | candela /candelas |
(TODO: metric vs us vs etc. tons)
Note: in SI, the base unit for mass is
kg
/kilograms
, notg
/grams
.k
/kilo
is provided as a convenience to allow for a mass base unit without a prefix. e.g.kilokilo
would be equivalent to1000(kilograms)
.
(TODO: exact durations of longer units. e.g. sidereal day vs solar day, etc.)
Note: the plural of
kelvin
iskelvin
, notkelvins
Named Derived Units
Quantity | Abbrev. Units | Full Units |
---|---|---|
Plane Angle | rad ° | radian /radians degree /degrees |
Solid Angle | sr | steradian /steradians |
Frequency | Hz | hertz |
Force / Weight | N lb /lbf | newton /newtons pound /pounds /pound-force /pounds-force |
Pressure / Stress | Pa atm bar psi torr mmHg inH2O | pascal /pascals atmosphere /atmospheres bar pounds_per_square_inch torr millimeters_of_mercury inches_of_water |
Energy / Work / Heat | J cal Cal *BTU eV Wh erg | joule /joules calorie /calories kilocalorie /kilocalories british_thermal_unit /british_thermal_units electron_volt /electron_volts watt_hour /watt_hours erg /ergs |
Power / Radiant Flux | W hp | watt /watts horsepower |
Electric Charge / Quantity of Electricity | C | coulomb /coulombs |
Voltage / Electrical Potential / EMF | V | volt /volts |
Capacitance | F | farad /farads |
Reistance / Impedance / Reactance | Ω | ohm /ohms |
Electrical Conductance | S | siemens |
Magnetic Flux | Wb | weber /webers |
Magnetic Flux Density | T | tesla /teslas |
Inductance | H | henry /henries |
Luminous Flux | lm | lumen /lumens |
Illuminance | lx | lux /luxes |
Radioactivity (Decays per unit time) | Bq | becquerel /becquerels |
Absorbed Dose (of Ionizing Radiation) | Gy | gray /grays |
Equivalent Dose (of Ionising Radiation) | Sv | sievert /sieverts |
Catalytic Activity | kat | katal /katals |
Note:
Cal
is equivalent tokcal
orkilocalorie
(i.e.1000(calories)
).
Weird Units
(TODO->all other units + weird units. e.g. drops)
Other Units
Quantity | Abbrev. Units | Full Units |
---|---|---|
Information | b /bit B /byte | bit /bits byte /bytes |
(TODO: where do decibels go? B
is already taken by byte
... perhaps the user can select what units get imported by importing units from different domains, e.g. import units from si
or import units from information
)
(TODO: other units to add: Hz
, liter
, gallon
, oz
, phon
/lufs
/other sound intensity related units)