Topic: Expressions

## Units

Calcpad provides a comprehensive support for physical units of measurement. The current version, supports metric (SI and compatible), US and Imperial units. There are seven basic units that correspond to the seven physical dimensions:

• mass - kilogram (kg)
• length - meter (m)
• time - second (s)
• electric current - ampere (A)
• temperature - degree Celsius (°C)
• amount of substance - mole (mol)
• luminous intensity - candela (cd)

All other units are derivative. They are obtained by the respective laws of physics. For example, force = mass·acceleration, so Newton is obtained by N = kg·m/s2. Multiples of units are also supported by adding the respective prefixes to units names. For example, kN = 103N, MN = 106N and so on.

Additionally, there are some "dimensionless" units like percents, permilles and angles (degrees, radians, etc.) that do not include any physical dimensions. However, angles exist in a special (eighth) non-physical dimension, in order not to cancel and convert to percents, when mixed (which would be weird).

You can attach units to numbers by typing the unit name after the value, e.g. 15kg. Then, you can use them in expressions, just like any other values. Unit cancellation and conversion is performed automatically during calculations. For example, the following expression will be evaluated as:

`1.23m + 35cm + 12mm = 1.59m` (and not: 1.23 + 35 + 12 = 48.23)

The result is usually obtained into the first unit in the expression. If you want to use particular units, write a vertical bar "|" followed by the target units at the end:

`1.23m + 35cm + 12mm|cm`

The above expression will evaluate to 159.2cm. If you simply want to convert units, just write the source and the target units, separated by a vertical bar, like: mm|cm or 10m/s|km/h.

Unit consistency is also verified automatically. For example, you cannot add m and s(e.g. 6m + 2s), but you can multiply and divide them 6m/2s = 3m/s.

Arguments for trigonometric, hyperbolic, logarithmic and exponential functions, must be unitless by definition. However, you can use units an any custom defined functions, if it makes any sense. You can also attach units to variables. If you specify the target units in a variable definition, they will be stored permanently inside the variable. Then, the selected units will be used further in the calculations with the respective value. In the next example, speed is calculated in m/s, but it is converted and stored as km/h:

Code Output
`'Distance -'s_1 = 50m`
`'Time -'t_1 = 2s`
`'Speed -'V = s_1/t_1|km/h`
`'What distance you will travel for't_2 = 5s'?`
`s _2 = V*t_2|m`
Distance - s1 = 50m
Time - t1 = 2s
Speed - V = s1/t1 = 50m/2s = 90km/h
What distance you will travel for t2 = 5s ?
s2 = V·t2 = 90km/h·5s = 125m

### Predefined units

Calcpad includes a large collection of predefined units as follows:

Dimensionless:

• Percent: %;
• Permille: ;

Metric (SI and compatible):

• Mass: ghgkgtktMtGtdgcgmgμgngpgDau;
• Length: mkmdmcmmmμmnmpmAUly;
• Time: smsμsnspsminhd;
• Frequency: HzkHzMHzGHzTHzmHzμHznHzpHzrpm;
• Speed: kmh;
• Electric current: AkAMAGATAmAμAnApA;
• Temperature: °CΔ°CK;
• Amount of substance: mol;
• Luminous intensity: cd;
• Volume:  LdaLhLdLcLmLμLnLpL;
• Force: dyn NdaNhNkNMNGNTNgfkgftf;
• Moment: NmkNm;
barmbarμbaratmatTorrmmHg;
• Viscosity: PcPStcSt;
• Energy work: JkJMJGJTJmJμJnJpJ
WhkWhMWhGWhTWhmWhμWhnWhpWh,
eVkeVMeVGeVTeVPeVEeVcalkcalerg;
• Power: WkWMWGWTWmWμWnWpWhpMks,
VAkVAMVAGVATVAmVAμVAnVApVA,
VARkVARMVARGVARTVARmVARμVARnVARpVAR;
• Electric charge: CkCMCGCTCmCμCnCpCAhmAh;
• Potential: VkVMVGVTVmVμVnVpV;
• Capacitance: FkFMFGFTFmFμFnFpF;
• Resistance: ΩμΩ;
• Conductance: SkSMSGSTSmSμSnSpSk℧M℧G℧T℧m℧μ℧n℧p℧;
• Magnetic flux: Wb kWbMWbGWbTWbmWbμWbnWbpWb;
• Magnetic flux density: TkTMTGTTTmTμTnTpT;
• Inductance: HkHMHGHTHmHμHnHpH;
• Luminous flux: lm;
• Illuminance: lx;
• Absorbed dose: GykGyMGyGGyTGymGyμGynGypGy;
• Equivalent dose: SvkSvMSvGSvTSvmSvμSvnSvpSv;
• Catalytic activity: kat;

Non-metric (Imperial/US):

• Mass: grdrozlb (or lbmlb_m), kipm (or kip_m), stqr,
cwt (or cwt_UKcwt_US), ton (or ton_UKton_US), slug;
• Length: thinftydchfurmiftm (or ftm_UKftm_US),
cable (or cable_UKcable_US) nmilirodpoleperchlea;
• Speed: mphknot;
• Temperature: °FΔ°F°R;
• Area: roodac;
• Volume, fluid: fl_oz, gi, pt, qt, gal, bbl, or:
fl_oz_UK, gi_UK, pt_UK, qt_UK, gal_UK, bbl_UK,
fl_oz_US, gi_US, pt_US, qt_US, gal_US, bbl_US;
Volume, dry: (US) pt_dry, (US) qt_dry, (US) gal_dry, (US) bbl_dry,
pk (or pk_UK, pk_US), bu (or bu_UK, bu_US);
• Force: ozf (or oz_f), lbf (or lb_f), kip (or kipfkip_f), tonf (or ton_f), pdl;
• Pressure: osiosf psipsfksiksftsitsfinHg;
• Energy/work: BTUtherm (or therm_UKtherm_US), quad;
• Power: hphpEhpS.

Angle units are accepted by trigonometric functions and they override all other settings. Inverse trigonometric functions return unitless values by default. If you want them to return the result in the current units, you have to define a variable: ReturnAngleUnits = 1.

Literals that follow numbers immediately are parsed as units, e.g. "2m". Standalone literals can be either units or variables, e.g. "N*m". The rules for parsing are as follows: If a literal has not been defined as a variable, it is parsed as a unit. Otherwise, it is parsed as a variable, even if a unit with the same name exists. If you put a dot before the literal, it will be parsed as a unit, even if a variable with the same name exists, e.g. ".N*.m".

### Custom units

You can define your own "custom" units and use them like any others in your code. Defining a unit is similar to defining a variable, but the name must be prefixed with a dot ".":

`.Name = expression`

Names can include somе currency symbols like: €, £, ₤, ¥, ¢, ₽, ₹, ₩, ₪. If you need to create a unit, that derive from others, you can write an expression with numbers and units on the right side. You can also define dimensionless units, like currency (USD, EUR, €, ₤) or information (bit, byte, KiB, etc), by specifying "= 1" for the first unit and setting the others as multiples. For example:

`  .bit = 1  .byte = 8*bit  .KiB = 1024*byte  ...`

Custom dimensionless units exist in a special (ninth) non-physical dimension. That is how they do not cancel or convert to other dimensionless units, like percents or angles, when mixed. However, if you have two types of dimensionless units in a single file, they will exist in the same dimension, so you should avoid mixing them.