File: si.go

package info (click to toggle)
golang-github-alecthomas-units 0.0~git20151022.0.2efee85-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch, stretch-backports
  • size: 84 kB
  • ctags: 56
  • sloc: makefile: 2
file content (26 lines) | stat: -rw-r--r-- 650 bytes parent folder | download | duplicates (3)
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
package units

// SI units.
type SI int64

// SI unit multiples.
const (
	Kilo SI = 1000
	Mega    = Kilo * 1000
	Giga    = Mega * 1000
	Tera    = Giga * 1000
	Peta    = Tera * 1000
	Exa     = Peta * 1000
)

func MakeUnitMap(suffix, shortSuffix string, scale int64) map[string]float64 {
	return map[string]float64{
		shortSuffix:  1,
		"K" + suffix: float64(scale),
		"M" + suffix: float64(scale * scale),
		"G" + suffix: float64(scale * scale * scale),
		"T" + suffix: float64(scale * scale * scale * scale),
		"P" + suffix: float64(scale * scale * scale * scale * scale),
		"E" + suffix: float64(scale * scale * scale * scale * scale * scale),
	}
}