mirror of
https://github.com/golang/go
synced 2024-11-06 06:26:13 -07:00
math/big: remove underscores from Binomial docs
Change-Id: I7605bcbbaa64bb4273ad458a157b1c6011467973 Reviewed-on: https://go-review.googlesource.com/c/go/+/447915 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
e6f662d7b0
commit
9860faa512
@ -206,13 +206,13 @@ func (z *Int) MulRange(a, b int64) *Int {
|
||||
}
|
||||
|
||||
// Binomial sets z to the binomial coefficient C(n, k) and returns z.
|
||||
func (z *Int) Binomial(n_, k_ int64) *Int {
|
||||
if k_ > n_ {
|
||||
func (z *Int) Binomial(n, k int64) *Int {
|
||||
if k > n {
|
||||
return z.SetInt64(0)
|
||||
}
|
||||
// reduce the number of multiplications by reducing k
|
||||
if k_ > n_-k_ {
|
||||
k_ = n_ - k_ // C(n, k) == C(n, n-k)
|
||||
if k > n-k {
|
||||
k = n - k // C(n, k) == C(n, n-k)
|
||||
}
|
||||
// C(n, k) == n * (n-1) * ... * (n-k+1) / k * (k-1) * ... * 1
|
||||
// == n * (n-1) * ... * (n-k+1) / 1 * (1+1) * ... * k
|
||||
@ -235,12 +235,12 @@ func (z *Int) Binomial(n_, k_ int64) *Int {
|
||||
// i++
|
||||
// z /= i
|
||||
// }
|
||||
var n, k, i, t Int
|
||||
n.SetInt64(n_)
|
||||
k.SetInt64(k_)
|
||||
var N, K, i, t Int
|
||||
N.SetInt64(n)
|
||||
K.SetInt64(k)
|
||||
z.Set(intOne)
|
||||
for i.Cmp(&k) < 0 {
|
||||
z.Mul(z, t.Sub(&n, &i))
|
||||
for i.Cmp(&K) < 0 {
|
||||
z.Mul(z, t.Sub(&N, &i))
|
||||
i.Add(&i, intOne)
|
||||
z.Quo(z, &i)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user