1---
2app_version: 0.5.0
3---
4# electronics-units.dplylib
5// Common units for electrical engineering / electronics.
6//
7// Import this library and use the units inline (12 V, 470 Ohm, 100 nF) or with
8// convert(): convert(1, "MOhm", "kOhm"), convert(100, "nF", "uF"), ...
9// Only units of the same kind convert into each other. A magnitude prefix
10// (p, n, u/µ, m, k, M, G, T) composes with any unit below automatically, so
11// only the base units need defining — nF/kOhm/mA and friends just work. The
12// ASCII alias "u" for micro composes this way; the "µ" spelling only works if
13// written out (see below), since it isn't a plain letter the prefix scan reads.
14
15# Base units
16defunit("A") // ampere — electric current
17defunit("V") // volt — voltage
18defunit("Ohm", "V/A") // resistance
19defunit("S", "A/V") // conductance — siemens (S = 1/Ω)
20defunit("F", "A*s/V") // capacitance — farad
21defunit("H", "V*s/A") // inductance — henry
22defunit("Ah", "A*h") // charge — ampere-hours (battery capacity)
23
24# "µ" spellings
25// A prefix in front of a symbol name isn't picked up automatically (5 µF is
26// not 0.000005 F) — each one needs its own defunit. Skip these and just write
27// the ASCII alias (uF, uA, ...) if that's not a concern.
28defunit("µA", 0.000001, "A")
29defunit("µV", 0.000001, "V")
30defunit("µF", 0.000001, "F")
31defunit("µH", 0.000001, "H")
32
33# Quick examples (visible when you open this file directly)
34convert(1, "MOhm", "kOhm") // 1000 kOhm
35convert(100, "nF", "uF") // 0.1 uF
36convert(2200, "uF", "mF") // 2.2 mF
37convert(1, "F", "pF") // 1e12 pF
38convert(2000, "mAh", "Ah") // 2 Ah
39