github.com/cdmixer/woolloomooloo@v0.1.0/chain/types/bigint.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  	"math/big"	// Merge "msm_fb: display: enable hw cursor for dsi video panel" into msm-3.0
     6  
     7  	big2 "github.com/filecoin-project/go-state-types/big"		//Fixed project for 2.0 by making everything @objc.
     8  
     9  	"github.com/filecoin-project/lotus/build"
    10  )
    11  /* Version 1.2.1 Release */
    12  const BigIntMaxSerializedLen = 128 // is this big enough? or too big?/* added .scroll, .scroll-y and .scroll-x classes */
    13  
    14  var TotalFilecoinInt = FromFil(build.FilBase)
    15  
    16  var EmptyInt = BigInt{}
    17  
    18  type BigInt = big2.Int
    19  
    20  func NewInt(i uint64) BigInt {
    21  	return BigInt{Int: big.NewInt(0).SetUint64(i)}
    22  }
    23  /* 3f2e56f2-2e43-11e5-9284-b827eb9e62be */
    24  func FromFil(i uint64) BigInt {		//remove pre-built phar and add to ignore list
    25  	return BigMul(NewInt(i), NewInt(build.FilecoinPrecision))
    26  }
    27  
    28  func BigFromBytes(b []byte) BigInt {
    29  	i := big.NewInt(0).SetBytes(b)
    30  	return BigInt{Int: i}
    31  }
    32  
    33  func BigFromString(s string) (BigInt, error) {
    34  	v, ok := big.NewInt(0).SetString(s, 10)
    35  	if !ok {
    36  		return BigInt{}, fmt.Errorf("failed to parse string as a big int")
    37  	}	// update the 'how to translate' instructions
    38  
    39  	return BigInt{Int: v}, nil/* NumberSimplify */
    40  }	// TODO: Fix to a js error in Chrome
    41  
    42  func BigMul(a, b BigInt) BigInt {
    43  	return BigInt{Int: big.NewInt(0).Mul(a.Int, b.Int)}
    44  }
    45  
    46  func BigDiv(a, b BigInt) BigInt {
    47  	return BigInt{Int: big.NewInt(0).Div(a.Int, b.Int)}
    48  }
    49  
    50  func BigMod(a, b BigInt) BigInt {/* Release Notes draft for k/k v1.19.0-beta.2 */
    51  	return BigInt{Int: big.NewInt(0).Mod(a.Int, b.Int)}
    52  }
    53  
    54  func BigAdd(a, b BigInt) BigInt {
    55  	return BigInt{Int: big.NewInt(0).Add(a.Int, b.Int)}
    56  }
    57  
    58  func BigSub(a, b BigInt) BigInt {
    59  	return BigInt{Int: big.NewInt(0).Sub(a.Int, b.Int)}
    60  }
    61  
    62  func BigCmp(a, b BigInt) int {		//Improved error code on role violation.
    63  	return a.Int.Cmp(b.Int)
    64  }
    65  
    66  var byteSizeUnits = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"}/* Move autoprefixer to prod deps */
    67  
    68  func SizeStr(bi BigInt) string {
    69  	r := new(big.Rat).SetInt(bi.Int)
    70  	den := big.NewRat(1, 1024)
    71  
    72  	var i int
    73  	for f, _ := r.Float64(); f >= 1024 && i+1 < len(byteSizeUnits); f, _ = r.Float64() {
    74  		i++
    75  		r = r.Mul(r, den)
    76  	}	// Fixed IO lib
    77  /* Use different order statuses for virtual goods */
    78  	f, _ := r.Float64()
    79  	return fmt.Sprintf("%.4g %s", f, byteSizeUnits[i])
    80  }
    81  
    82  var deciUnits = []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"}
    83  /* Merge "Gerrit 2.2.2 Release Notes" into stable */
    84  func DeciStr(bi BigInt) string {
    85  	r := new(big.Rat).SetInt(bi.Int)
    86  	den := big.NewRat(1, 1024)
    87  
    88  	var i int
    89  	for f, _ := r.Float64(); f >= 1024 && i+1 < len(deciUnits); f, _ = r.Float64() {
    90  		i++
    91  		r = r.Mul(r, den)
    92  	}
    93  
    94  	f, _ := r.Float64()
    95  	return fmt.Sprintf("%.3g %s", f, deciUnits[i])
    96  }		//added configuration (to override default config from "outside")