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 and kg are valid, but kgrams and kilog are invalid.

PrefixAbbrev.Scale
yottaY10^24
zettaZ10^21
exaE10^18
petaP10^15
teraT10^12
gigaG10^9
megaM10^6
kilok10^3
hectoh10^2
decada10^1
decid10^−1
centic10^−2
millim10^−3
microμ/u10^−6
nanon10^−9
picop10^−12
femtof10^−15
attoa10^−18
zeptoz10^−21
yoctoy10^−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)

PrefixAbbrev.Scale
kibiKi2^10
mebiMi2^20
gibiGi2^30
tebiTi2^40
pebiPi2^50
exbiEi2^60
zebiZi2^70
yobiYi2^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

QuantitySymbolAbbrev. UnitsFull 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]Aamp/amps/ampere/amperes
Thermodynamic Temperature[Θ]K
°R/°Ra
°C
°F
kelvin
rankine/degrees_rankine
celsius/degrees_celsius
fahrenheit/degrees_fahrenheit
Amount of Substance[N]molmole/moles
Luminous Intensity[J]cdcandela/candelas

(TODO: metric vs us vs etc. tons)

Note: in SI, the base unit for mass is kg/kilograms, not g/grams. k/kilo is provided as a convenience to allow for a mass base unit without a prefix. e.g. kilokilo would be equivalent to 1000(kilograms).

(TODO: exact durations of longer units. e.g. sidereal day vs solar day, etc.)

Note: the plural of kelvin is kelvin, not kelvins

Named Derived Units

QuantityAbbrev. UnitsFull Units
Plane Anglerad
°
radian/radians
degree/degrees
Solid Anglesrsteradian/steradians
FrequencyHzhertz
Force / WeightN
lb/lbf
newton/newtons
pound/pounds/pound-force/pounds-force
Pressure / StressPa
atm
bar
psi
torr
mmHg
inH2O
pascal/pascals
atmosphere/atmospheres
bar
pounds_per_square_inch
torr
millimeters_of_mercury
inches_of_water
Energy / Work / HeatJ
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 FluxW
hp
watt/watts
horsepower
Electric Charge / Quantity of ElectricityCcoulomb/coulombs
Voltage / Electrical Potential / EMFVvolt/volts
CapacitanceFfarad/farads
Reistance / Impedance / ReactanceΩohm/ohms
Electrical ConductanceSsiemens
Magnetic FluxWbweber/webers
Magnetic Flux DensityTtesla/teslas
InductanceHhenry/henries
Luminous Fluxlmlumen/lumens
Illuminancelxlux/luxes
Radioactivity (Decays per unit time)Bqbecquerel/becquerels
Absorbed Dose (of Ionizing Radiation)Gygray/grays
Equivalent Dose (of Ionising Radiation)Svsievert/sieverts
Catalytic Activitykatkatal/katals

Note: Cal is equivalent to kcal or kilocalorie (i.e. 1000(calories)).

Weird Units

(TODO->all other units + weird units. e.g. drops)

Other Units

QuantityAbbrev. UnitsFull Units
Informationb/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)