-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsi-units.lisp
78 lines (77 loc) · 5.78 KB
/
si-units.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
(in-package :pq)
(defun define-si-units (&key clear-existing-units)
(when clear-existing-units
(clear-units))
(define-unit-prefix |yocto| -24 :abbrev |y|)
(define-unit-prefix |zepto| -21 :abbrev |z|)
(define-unit-prefix |atto| -18 :abbrev |a|)
(define-unit-prefix |femto| -15 :abbrev |f|)
(define-unit-prefix |pico| -12 :abbrev |p|)
(define-unit-prefix |nano| -9 :abbrev |n|)
(define-unit-prefix |micro| -6 :abbrev |u|)
(define-unit-prefix |milli| -3 :abbrev |m|)
(define-unit-prefix |centi| -2 :abbrev |c|)
(define-unit-prefix |deci| -1 :abbrev |d|)
(define-unit-prefix |deca| 1 :abbrev |da|)
(define-unit-prefix |hecto| 2 :abbrev |h|)
(define-unit-prefix |kilo| 3 :abbrev |k|)
(define-unit-prefix |mega| 6 :abbrev |M|)
(define-unit-prefix |giga| 9 :abbrev |G|)
(define-unit-prefix |tera| 12 :abbrev |T|)
(define-unit-prefix |peta| 15 :abbrev |P|)
(define-unit-prefix |exa| 18 :abbrev |E|)
(define-unit-prefix |zetta| 21 :abbrev |Z|)
(define-unit-prefix |yotta| 24 :abbrev |Y|)
(define-unit-prefix |kibi| 1 :abbrev |Ki| :base 1024)
(define-unit-prefix |mebi| 2 :abbrev |Mi| :base 1024)
(define-unit-prefix |gibi| 3 :abbrev |Gi| :base 1024)
(define-unit-prefix |tebi| 4 :abbrev |Ti| :base 1024)
(define-unit-prefix |pebi| 5 :abbrev |Pi| :base 1024)
(define-unit-prefix |exbi| 6 :abbrev |Ei| :base 1024)
(define-unit-prefix |zebi| 7 :abbrev |Zi| :base 1024)
(define-unit-prefix |yobi| 8 :abbrev |Yi| :base 1024)
;; SI base units
(define-unit |metre| :abbrev |m| :alias (|meter| |metres| |meters|) :prefix-test (prefix-range 10 nil 3))
(define-unit |gram| :abbrev |g| :alias |grams| :prefix-test (prefix-and (prefix-base 10 3) (prefix-range 10 nil 3)))
(define-unit |second| :abbrev |s| :alias |seconds| :prefix-test (prefix-range 10 nil -3))
(define-unit |ampere| :abbrev |A| :alias |amperes| :prefix-test (prefix-and (prefix-base 10 3) (prefix-range 10 nil 3)))
(define-unit |kelvin| :abbrev |K| :prefix-test (prefix-base 10 3))
(define-unit |mole| :abbrev |mol| :alias |moles| :prefix-test (prefix-base 10))
(define-unit |candela| :abbrev |cd| :prefix-test (prefix-base 10 3))
;; Named units derived from SI base units
(define-unit |radian| :def ((/ 180 pi) |degree|) :abbrev |rad| :prefix-test (prefix-range 10 nil -3))
(define-unit |steradian| :def (1) :abbrev |sr| :prefix-test (prefix-range 10 nil -3))
(define-unit |hertz| :def (1 / |second|) :abbrev |Hz| :prefix-test (prefix-base 10 3))
(define-unit |newton| :def (1 |kilogram| |metre| / |second| ^ 2) :abbrev |N| :prefix-test (prefix-base 10 3))
(define-unit |pascal| :def (1 |newton| / |metre| ^ 2) :abbrev |Pa| :prefix-test (prefix-base 10 3))
(define-unit |joule| :def (1 |newton| |metre|) :alias |joules| :abbrev |J| :prefix-test (prefix-base 10 3))
(define-unit |watt| :def (1 |joule| / |second|) :alias |watts| :abbrev |W| :prefix-test (prefix-base 10 3))
(define-unit |coulomb| :def (1 |ampere| |second|) :abbrev |C| :prefix-test (prefix-base 10 3))
(define-unit |volt| :def (1 |watt| / |ampere|) :alias |volts| :abbrev |V| :prefix-test (prefix-and (prefix-base 10 3) (prefix-range 10 nil 15)))
(define-unit |farad| :def (1 |coulomb| / |volt|) :abbrev |F| :prefix-test (prefix-and (prefix-base 10 3) (prefix-range 10 nil 3)))
(define-unit |ohm| :def (1 |volt| / |ampere|) :alias |ohms| :prefix-test (prefix-base 10 3))
(define-unit |siemens| :def (1 |ampere| / |volt|) :abbrev |S| :prefix-test (prefix-base 10 3))
(define-unit |weber| :def (1 |volt| |second|) :abbrev |Wb| :prefix-test (prefix-base 10 3))
(define-unit |tesla| :def (1 |weber| / |metre| ^ 2) :abbrev |T| :prefix-test (prefix-base 10 3))
(define-unit |henry| :def (1 |weber| / |ampere|) :abbrev |H| :prefix-test (prefix-base 10 3))
(define-unit |celsius| :def (1 |kelvin|) :prefix-test (prefix-base 10 3))
(define-unit |lumen| :def (1 |candela| |steradian|) :alias |lumens| :abbrev |lm| :prefix-test (prefix-base 10 3))
(define-unit |lux| :def (1 |lumen| / |metre| ^ 2) :abbrev |lx| :prefix-test (prefix-base 10 3))
(define-unit |becquerel| :def (1 / |second|) :alias |becquerels| :abbrev |Bq| :prefix-test (prefix-base 10 3))
(define-unit |gray| :def (1 |joule| / |kilogram|) :alias |grays| :abbrev |Gy| :prefix-test (prefix-base 10 3))
(define-unit |sievert| :def (1 |joule| / |kilogram|) :alias |sieverts| :abbrev |Sv| :prefix-test (prefix-base 10 3))
(define-unit |katal| :def (1 |mol| / |second|) :abbrev |kat| :prefix-test (prefix-base 10 3))
(define-unit |byte| :def (1) :alias |bytes| :abbrev |b| :prefix-test (prefix-or (prefix-base 1024) (prefix-range 10 3 nil)))
;; Non-SI units accepted for use with SI
(define-unit |minute| :def (60 |second|) :alias |minutes| :abbrev |min| :prefix-test (constantly nil))
(define-unit |hour| :def (60 |minute|) :alias |hours| :abbrev |h| :prefix-test (constantly nil))
(define-unit |day| :def (24 |hour|) :alias |days| :abbrev |d| :prefix-test (constantly nil))
(define-unit |degree| :def (1) :alias |degrees| :abbrev |deg| :prefix-test (prefix-range 10 nil -3))
(define-unit |hectare| :def (10000 |metre| ^ 2) :alias |hectares| :abbrev |ha| :prefix-test (constantly nil))
(define-unit |litre| :def (1 |decimetre| ^ 3) :alias (|liter| |litres| |liters|) :abbrev (|l| |L|) :prefix-test (prefix-range 10 nil 2))
(define-unit |tonne| :def (1000 |kilogram|) :alias |tonnes| :prefix-test (prefix-range 10 3 nil))
(define-unit |au| :def (149597870700 |metre|) :prefix-test (constantly nil))
(define-unit |electron| :def (1.6021765314d-19 |coulomb|) :alias |electrons| :abbrev |e| :prefix-test (prefix-range 10 3 nil))
(define-unit |electronvolt| :def (1 |electron| |volt|) :alias |electronvolts| :abbrev |eV| :prefix-test (prefix-base 10 3))
(define-unit |dalton| :def (1.6605388628d-27 |kilogram|) :alias |daltons| :abbrev (|u| |Da|) :prefix-test (constantly nil)))
(export 'define-si-units)