Topic: Expressions
Online Help
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.
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 |
Calcpad includes a large collection of predefined units as follows:
Dimensionless:
- Percent: %;
- Permille: ‰;
- Angles: °, ′, ″, deg, rad, grad, rev;
Metric units (SI and compatible):
- Mass: g, hg, kg, t, kt, Mt, Gt, dg, cg, mg, μg, ng, pg, Da, u;
- Length: m, km, dm, cm, mm, μm, nm, pm, AU, ly;
- Time: s, ms, μs, ns, ps, min, h, d;
- Frequency: Hz, kHz, MHz, GHz, THz, mHz, μHz, nHz, pHz, rpm;
- Speed: kmh;
- Electric current: A, kA, MA, GA, TA, mA, μA, nA, pA;
- Temperature: °C, Δ°C, K;
- Amount of substance: mol;
- Luminous intensity: cd;
- Area: a, daa, ha;
- Volume: L, mL, cL, dL, hL;
- Force: dyn N, daN, hN, kN, MN, GN, TN, gf, kgf, tf;
- Moment: Nm, kNm;
- Pressure: Pa, daPa, hPa, kPa, MPa, GPa, TPa, dPa, cPa, mPa, μPa, nPa, pPa,
bar, mbar, μbar, atm, at, Torr, mmHg; - Viscosity: P, cP, St, cSt;
- Energy work: J, kJ, MJ, GJ, TJ, mJ, μJ, nJ, pJ, Wh, kWh, MWh, GWh, TWh, cal, kcal, erg,
eV, keV, MeV, GeV, TeV, PeV, EeV; - Power: W, kW, MW, GW, TW, mW, μW, nW, pW, hpM, ks,
VA, kVA, MVA, GVA, TVA, mVA, μVA, nVA, pVA,
VAR, kVAR, MVAR, GVAR, TVAR, mVAR, μVAR, nVAR, pVAR; - Electric charge: C, kC, MC, GC, TC, mC, μC, nC, pC, Ah, mAh;
- Potential: V, kV, MV, GV, TV, mV, μV, nV, pV;
- Capacitance: F, kF, MF, GF, TF, mF, μF, nF, pF;
- Resistance: Ω, kΩ, MΩ, GΩ, TΩ, mΩ, μΩ, nΩ, pΩ;
- Conductance: S, kS, MS, GS, TS, mS, μS, nS, pS, ℧, k℧, M℧, G℧, T℧, m℧, μ℧, n℧, p℧;
- Magnetic flux: Wb , kWb, MWb, GWb, TWb, mWb, μWb, nWb, pWb;
- Magnetic flux density: T, kT, MT, GT, TT, mT, μT, nT, pT;
- Inductance: H, kH, MH, GH, TH, mH, μH, nH, pH;
- Luminous flux: lm;
- Illuminance: lx;
- Radioactivity: Bq, kBq, MBq, GBq, TBq, mBq, μBq, nBq, pBq, Ci, Rd;
- Absorbed dose: Gy, kGy, MGy, GGy, TGy, mGy, μGy, nGy, pGy;
- Equivalent dose: Sv, kSv, MSv, GSv, TSv, mSv, μSv, nSv, pSv;
- Catalytic activity: kat;
Non-metric units (Imperial/US):
- Mass: gr, dr, oz, lb, kip, st, qr, cwt, cwt_UK, cwt_US, ton, ton_UK, ton_US, slug;
- Length: th, in, ft, yd, ch, fur, mi, ftm, cable, nmi, li, rod, pole, perch, lea;
- Speed: mph, knot;
- Temperature: °F, Δ°F, °R;
- Area: rood, ac;
- Volume (fluid): fl_oz, gi, pt, qt, gal, bbl, (dry) bu;
fl_oz_UK, gi_UK, pt_UK, qt_UK, gal_UK, bbl_UK, (dry) bu_UK;
fl_oz_US, gi_US, pt_US, qt_US, gal_US, bbl_US, (dry) bu_US; - Force: ozf, lbf, kipf, tonf, pdl;
- Pressure: osi, osf psi, psf, ksi, ksf, tsi, tsf, inHg;
- Energy/work: BTU, therm, therm_UK, therm_US, quad;
- Power: hp, hpE, hpS.
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 are written immediately after numbers are recognized as units by the parser, 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". In this way, you can also distinguish between the "%" unit and the reminder operator that uses the same symbol. The unit must start with a dot ".%".