Quantities

functions related to Quantities, physical units and constants


Functions

Predicates

Constants


The Quantities module provides comprehensive support for physical quantities and units. It includes a wide range of physical properties, SI units, derived units, and constants, with automatic unit conversion and dimensional analysis.

Key Concepts

  • Physical quantities with units (like "5 meters" or "72 kilometers per hour")
  • Support for all SI base units and derived units
  • Automatic unit conversion and compatibility checking
  • Physical constants
  • Dimensional analysis
  • Support for currency units

Basic Usage

Creating Quantities

; basic quantities
distance: 100`m         ; 100 meters
time: 9.5`s             ; 9.5 seconds
mass: 75`kg             ; 75 kilograms

; derived units
speed: 60`km/h          ; 60 kilometers per hour
force: 10`N             ; 10 newtons
energy: 50`kWh          ; 50 kilowatt-hours

Unit Conversions

dist: 5`km
print convert dist `m           ; 5000 m

; or using the infix operator
print dist --> `m               ; 5000 m

speed: 90`km/h
print speed --> `m/s            ; 25 m/s

temp: 25`degC
print temp --> `degF            ; 77°F

Unit Compatibility

length1: 5`m
length2: 3`km

; compatible units can be used in calculations
total: length1 + (length2 --> `m)
print total                    ; 3005 m

speed: 100`km/h
time: 2.5`h

; dimensional analysis works automatically
distance: speed * time
print distance                 ; 250 km

Working with Currencies

price: 50`USD
euros: price --> `EUR
print euros                    ; 47.77 € (depends on the current
                               ;          exchange rate, obviously...)

salary: 5000`USD/mo
yearly: salary * 12
print yearly                   ; 60000 $/mo

Common Patterns

Complex Unit Calculations

; calculating power
voltage: 220`V
current: 5`A
power: voltage * current
print power                    ; 1100 V·A

; calculating energy cost
time: 2`h
energy: power * time
price: 0.15`USD/kWh
cost: price * (energy --> `kWh)
print cost                     ; 0.33 $

Using Physical Constants

; gravitational force
G: gravitationalConstant
m1: 5.97e24`kg                  ; mass of Earth
m2: 75`kg                       ; mass of a person
r: 6371000`m                    ; Earth's radius
force: G * m1 * m2 / (r * r)
print to :floating force        ; 736.2513565961324

Available Properties

Physical quantities in Arturo are classified by their properties. Here are some key properties and their dimensions:

PropertyDimensionsExample
LengthL5m
TimeT10s
MassM75kg
CurrentI5A
TemperatureK20degC
AmountN2mol
LuminosityJ100cd
SpeedL·T⁻¹60km/h
AccelerationL·T⁻²9.81m/s2
ForceL·M·T⁻²10N
EnergyL²·M·T⁻²100J
PowerL²·M·T⁻³1000W

Note
There are many more properties available. Use property to inspect any quantity's dimensional formula.

Prefixes

Metric prefixes are supported for most units:

PrefixSymbolFactor
attoa10⁻¹⁸
femtof10⁻¹⁵
picop10⁻¹²
nanon10⁻⁹
microμ10⁻⁶
millim10⁻³
kilok10³
megaM10⁶
gigaG10⁹
teraT10¹²
petaP10¹⁵
exaE10¹⁸

Note
Most units that allow prefixes can use any SI prefix (from atto- to exa-). Prefixes change the unit by the corresponding power of 10.

Supported Units

Base SI Units

UnitSymbolPropertyExample
metermLength5m
secondsTime10s
kelvinKTemperature300K
gramgMass500g
ampereACurrent2A
molemolSubstance1mol
candelacdLuminosity100cd

Length Units

UnitSymbolDefinitionNote
inchin127/5000 m
footft12 in
yardyd3 ft
milemi5280 ft
nautical milenmi1852 m
angstromÅ10⁻¹⁰ m
light yearly9.461e15 m
astronomical unitau1.496e11 m
pixelpx1/96 in
pointpt1/72 in

Area Units

UnitSymbolDefinition
acreac4840 yd²
hectareha10000 m²
barnb100 ftm²

Volume Units

UnitSymbolDefinition
literL1000 cm³
gallongal231 in³
barrelbbl42 gal
quartqt1/4 gal
pintp1/2 qt
cupcup1/2 p
fluid ouncefloz1/8 cup
bushelbu2150.42 in³
cordcord128 ft³

Mass Units

UnitSymbolDefinition
poundlb0.45359237 kg
ounceoz1/16 lb
stonest14 lb
tonton2000 lb
metric tont1000 kg
caratct0.2 g
graingr64.79891 mg

Time Units

UnitSymbolDefinition
minutemin60 s
hourh60 min
dayday24 h
weekwk7 day
monthmo2629746 s
yearyr31556952 s

Speed Units

UnitSymbolDefinition
kilometers per hourkm/h1000/3600 m/s
miles per hourmph5280/3600 ft/s
knotkn1852/3600 m/s
machmach340.29 m/s

Force Units

UnitSymbolDefinition
newtonN1 kg·m/s²
dynedyn10⁻⁵ N
pound-forcelbf4.44822 N

Pressure Units

UnitSymbolDefinition
pascalPa1 N/m²
barbar100000 Pa
atmosphereatm101325 Pa
torrTorr133.3224 Pa
psipsi6894.76 Pa

Energy Units

UnitSymbolDefinition
jouleJ1 N·m
watt-hourWh3600 J
caloriecal4.184 J
electron volteV1.602e-19 J
BTUBTU1055.06 J

Power Units

UnitSymbolDefinition
wattW1 J/s
horsepowerhp745.7 W

Electric Units

UnitSymbolDefinition
voltV1 W/A
ohmΩ1 V/A
faradF1 C/V
henryH1 V·s/A
weberWb1 V·s
teslaT1 Wb/m²

Angle Units

UnitSymbolDefinition
radianradbase unit
degree°π/180 rad
arcminute'π/10800 rad
arcsecond"π/648000 rad

Radiation Units

UnitSymbolDefinition
becquerelBq1/s
grayGy1 J/kg
sievertSv1 J/kg

Information Units

UnitSymbolDefinition
byteBbase unit
bitb1/8 B
kibibyteKiB1024 B
mebibyteMiB1024 KiB
gibibyteGiB1024 MiB
tebibyteTiB1024 GiB

Tip
Arturo supports many world currencies including: AED, ALL, ARS, AUD, BGN, BHD, BND, BOB, BRL, BWP, CAD, CHF, CLP, CNY, COP, CRC, CZK, DKK, DOP, DZD, EGP, ETB, EUR, FJD, GBP, HKD, HNL, HRK, HUF, IDR, ILS, INR, IRR, ISK, JMD, JOD, JPY, KES, KRW, KWD, KYD, KZT, LBP, LKR, MAD, MDL, MKD, MXN, MUR, MYR, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG, QAR, RON, RSD, RUB, SAR, SCR, SEK, SGD, SLL, SOS, SVC, THB, TND, TRY, TTD, TWD, TZS, UAH, UGX, UYU, UZS, VES, VND, XAF, XOF, YER, ZAR, ZMW.

Cryptocurrency codes are also supported: BTC (Bitcoin), ETH (Ethereum), BNB (Binance Coin).