Skip to content

Commit 463a095

Browse files
maximaldustin
authored andcommitted
Add new SI and IEC prefixes: ronto, quecto, ronna, quetta
1 parent bd075d4 commit 463a095

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

bigbytes.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ var (
2828
BigZiByte = (&big.Int{}).Mul(BigEiByte, bigIECExp)
2929
// BigYiByte is 1,024 z bytes in bit.Ints
3030
BigYiByte = (&big.Int{}).Mul(BigZiByte, bigIECExp)
31+
// BigRiByte is 1,024 y bytes in bit.Ints
32+
BigRiByte = (&big.Int{}).Mul(BigYiByte, bigIECExp)
33+
// BigQiByte is 1,024 r bytes in bit.Ints
34+
BigQiByte = (&big.Int{}).Mul(BigRiByte, bigIECExp)
3135
)
3236

3337
var (
@@ -51,6 +55,10 @@ var (
5155
BigZByte = (&big.Int{}).Mul(BigEByte, bigSIExp)
5256
// BigYByte is 1,000 SI z bytes in big.Ints
5357
BigYByte = (&big.Int{}).Mul(BigZByte, bigSIExp)
58+
// BigRByte is 1,000 SI y bytes in big.Ints
59+
BigRByte = (&big.Int{}).Mul(BigYByte, bigSIExp)
60+
// BigQByte is 1,000 SI r bytes in big.Ints
61+
BigQByte = (&big.Int{}).Mul(BigRByte, bigSIExp)
5462
)
5563

5664
var bigBytesSizeTable = map[string]*big.Int{
@@ -71,6 +79,10 @@ var bigBytesSizeTable = map[string]*big.Int{
7179
"zb": BigZByte,
7280
"yib": BigYiByte,
7381
"yb": BigYByte,
82+
"rib": BigRiByte,
83+
"rb": BigRByte,
84+
"qib": BigQiByte,
85+
"qb": BigQByte,
7486
// Without suffix
7587
"": BigByte,
7688
"ki": BigKiByte,
@@ -89,6 +101,10 @@ var bigBytesSizeTable = map[string]*big.Int{
89101
"zi": BigZiByte,
90102
"y": BigYByte,
91103
"yi": BigYiByte,
104+
"r": BigRByte,
105+
"ri": BigRiByte,
106+
"q": BigQByte,
107+
"qi": BigQiByte,
92108
}
93109

94110
var ten = big.NewInt(10)
@@ -115,7 +131,7 @@ func humanateBigBytes(s, base *big.Int, sizes []string) string {
115131
//
116132
// BigBytes(82854982) -> 83 MB
117133
func BigBytes(s *big.Int) string {
118-
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
134+
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "RB", "QB"}
119135
return humanateBigBytes(s, bigSIExp, sizes)
120136
}
121137

@@ -125,7 +141,7 @@ func BigBytes(s *big.Int) string {
125141
//
126142
// BigIBytes(82854982) -> 79 MiB
127143
func BigIBytes(s *big.Int) string {
128-
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
144+
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "RiB", "QiB"}
129145
return humanateBigBytes(s, bigIECExp, sizes)
130146
}
131147

si.go

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
)
99

1010
var siPrefixTable = map[float64]string{
11+
-30: "q", // quecto
12+
-27: "r", // ronto
1113
-24: "y", // yocto
1214
-21: "z", // zepto
1315
-18: "a", // atto
@@ -25,6 +27,8 @@ var siPrefixTable = map[float64]string{
2527
18: "E", // exa
2628
21: "Z", // zetta
2729
24: "Y", // yotta
30+
27: "R", // ronna
31+
30: "Q", // quetta
2832
}
2933

3034
var revSIPrefixTable = revfmap(siPrefixTable)

si_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ func TestSI(t *testing.T) {
1111
num float64
1212
formatted string
1313
}{
14+
{"e-30", 1e-30, "1 qF"},
15+
{"e-27", 1e-27, "1 rF"},
1416
{"e-24", 1e-24, "1 yF"},
1517
{"e-21", 1e-21, "1 zF"},
1618
{"e-18", 1e-18, "1 aF"},
@@ -54,6 +56,8 @@ func TestSI(t *testing.T) {
5456
{"e+18", 2.2e+18, "2.2 EF"},
5557
{"e+21", 2.2e+21, "2.2 ZF"},
5658
{"e+24", 2.2e+24, "2.2 YF"},
59+
{"e+27", 2.2e+27, "2.2 RF"},
60+
{"e+30", 2.2e+30, "2.2 QF"},
5761

5862
// special case
5963
{"1F", 1000 * 1000, "1 MF"},

0 commit comments

Comments
 (0)