gitee.com/lonely0422/gometalinter.git@v3.0.1-0.20190307123442-32416ab75314+incompatible/_linters/src/github.com/nbutton23/zxcvbn-go/utils/math/mathutils.go (about)

     1  package zxcvbn_math
     2  
     3  import "math"
     4  
     5  /**
     6  I am surprised that I have to define these. . . Maybe i just didn't look hard enough for a lib.
     7  */
     8  
     9  //http://blog.plover.com/math/choose.html
    10  func NChoseK(n, k float64) float64 {
    11  	if k > n {
    12  		return 0
    13  	} else if k == 0 {
    14  		return 1
    15  	}
    16  
    17  	var r float64 = 1
    18  
    19  	for d := float64(1); d <= k; d++ {
    20  		r *= n
    21  		r /= d
    22  		n--
    23  	}
    24  
    25  	return r
    26  }
    27  
    28  func Round(val float64, roundOn float64, places int) (newVal float64) {
    29  	var round float64
    30  	pow := math.Pow(10, float64(places))
    31  	digit := pow * val
    32  	_, div := math.Modf(digit)
    33  	if div >= roundOn {
    34  		round = math.Ceil(digit)
    35  	} else {
    36  		round = math.Floor(digit)
    37  	}
    38  	newVal = round / pow
    39  	return
    40  }