aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/nbutton23/zxcvbn-go/utils/math/mathutils.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/nbutton23/zxcvbn-go/utils/math/mathutils.go')
-rw-r--r--vendor/github.com/nbutton23/zxcvbn-go/utils/math/mathutils.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/github.com/nbutton23/zxcvbn-go/utils/math/mathutils.go b/vendor/github.com/nbutton23/zxcvbn-go/utils/math/mathutils.go
new file mode 100644
index 000000000..1b989d194
--- /dev/null
+++ b/vendor/github.com/nbutton23/zxcvbn-go/utils/math/mathutils.go
@@ -0,0 +1,40 @@
+package zxcvbnmath
+
+import "math"
+
+/*
+NChoseK http://blog.plover.com/math/choose.html
+I am surprised that I have to define these. . . Maybe i just didn't look hard enough for a lib.
+*/
+func NChoseK(n, k float64) float64 {
+ if k > n {
+ return 0
+ } else if k == 0 {
+ return 1
+ }
+
+ var r float64 = 1
+
+ for d := float64(1); d <= k; d++ {
+ r *= n
+ r /= d
+ n--
+ }
+
+ return r
+}
+
+// Round a number
+func Round(val float64, roundOn float64, places int) (newVal float64) {
+ var round float64
+ pow := math.Pow(10, float64(places))
+ digit := pow * val
+ _, div := math.Modf(digit)
+ if div >= roundOn {
+ round = math.Ceil(digit)
+ } else {
+ round = math.Floor(digit)
+ }
+ newVal = round / pow
+ return
+}