-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit_symbols.go
executable file
·105 lines (95 loc) · 2.84 KB
/
unit_symbols.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package bitty
/*
Copyright 2020 IBM
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// UnitSymbol represents the measurement symbol of a binary measurement as dictated by the SI
type UnitSymbol string
// SI symbols for binary measurements including notation for former IEC measurements
const (
Bit UnitSymbol = "Bit"
Byte UnitSymbol = "Byte"
Kib UnitSymbol = "Kib"
Mib UnitSymbol = "Mib"
Gib UnitSymbol = "Gib"
Tib UnitSymbol = "Tib"
Pib UnitSymbol = "Pib"
Eib UnitSymbol = "Eib"
Zib UnitSymbol = "Zib"
Yib UnitSymbol = "Yib"
KiB UnitSymbol = "KiB"
MiB UnitSymbol = "MiB"
GiB UnitSymbol = "GiB"
TiB UnitSymbol = "TiB"
PiB UnitSymbol = "PiB"
EiB UnitSymbol = "EiB"
ZiB UnitSymbol = "ZiB"
YiB UnitSymbol = "YiB"
db UnitSymbol = "db"
hb UnitSymbol = "hb"
kb UnitSymbol = "kb"
Mb UnitSymbol = "Mb"
Gb UnitSymbol = "Gb"
Tb UnitSymbol = "Tb"
Pb UnitSymbol = "Pb"
Eb UnitSymbol = "Eb"
Zb UnitSymbol = "Zb"
Yb UnitSymbol = "Yb"
dB UnitSymbol = "dB"
hB UnitSymbol = "hB"
kB UnitSymbol = "kB"
MB UnitSymbol = "MB"
GB UnitSymbol = "GB"
TB UnitSymbol = "TB"
PB UnitSymbol = "PB"
EB UnitSymbol = "EB"
ZB UnitSymbol = "ZB"
YB UnitSymbol = "YB"
)
// UnitStandard represents a standard for unit measurement. Currently SI 9th
// edition is the supported standard, with SI notation for IEC binary and
// decimal formats
type UnitStandard int
// Unit Standard enums
const (
SI UnitStandard = iota
IEC
)
// UnitSymbolPair holds the least and greatest UnitSymbol for a given standard
// and exponent
type UnitSymbolPair interface {
Standard() UnitStandard
Exponent() int
Least() UnitSymbol
Greatest() UnitSymbol
}
var unitSymbolPairs = []UnitSymbolPair{
NewBaseUnitSymbolPair(SI),
NewBaseUnitSymbolPair(IEC),
NewIECUnitSymbolPair(Kib, KiB, 1),
NewIECUnitSymbolPair(Mib, MiB, 2),
NewIECUnitSymbolPair(Gib, GiB, 3),
NewIECUnitSymbolPair(Tib, TiB, 4),
NewIECUnitSymbolPair(Pib, PiB, 5),
NewIECUnitSymbolPair(Eib, EiB, 6),
NewIECUnitSymbolPair(Zib, ZiB, 7),
NewIECUnitSymbolPair(Yib, YiB, 8),
NewSIUnitSymbolPair(db, dB, 1),
NewSIUnitSymbolPair(hb, hB, 2),
NewSIUnitSymbolPair(kb, kB, 3),
NewSIUnitSymbolPair(Mb, MB, 6),
NewSIUnitSymbolPair(Gb, GB, 9),
NewSIUnitSymbolPair(Tb, TB, 12),
NewSIUnitSymbolPair(Pb, PB, 15),
NewSIUnitSymbolPair(Eb, EB, 18),
NewSIUnitSymbolPair(Zb, ZB, 21),
NewSIUnitSymbolPair(Yb, YB, 24),
}