blob: f49dc337dcd7318c6e827b81b5020a5715c41bfd [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001package humanize
2
3import (
4 "math/big"
5)
6
7// order of magnitude (to a max order)
8func oomm(n, b *big.Int, maxmag int) (float64, int) {
9 mag := 0
10 m := &big.Int{}
11 for n.Cmp(b) >= 0 {
12 n.DivMod(n, b, m)
13 mag++
14 if mag == maxmag && maxmag >= 0 {
15 break
16 }
17 }
18 return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag
19}
20
21// total order of magnitude
22// (same as above, but with no upper limit)
23func oom(n, b *big.Int) (float64, int) {
24 mag := 0
25 m := &big.Int{}
26 for n.Cmp(b) >= 0 {
27 n.DivMod(n, b, m)
28 mag++
29 }
30 return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag
31}