mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-22 12:46:03 +03:00
Update profile.go
This commit is contained in:
parent
bd27cda490
commit
7759f2ede9
@ -10,3 +10,16 @@ func Duration(invocation time.Time, name string) {
|
|||||||
|
|
||||||
log.Printf("%s lasted %s", name, elapsed)
|
log.Printf("%s lasted %s", name, elapsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BigIntFactorial(x big.Int) *big.Int {
|
||||||
|
// Arguments to a defer statement is immediately evaluated and stored.
|
||||||
|
// The deferred function receives the pre-evaluated values when its invoked.
|
||||||
|
defer Duration(time.Now(), "IntFactorial")
|
||||||
|
|
||||||
|
y := big.NewInt(1)
|
||||||
|
for one := big.NewInt(1); x.Sign() > 0; x.Sub(x, one) {
|
||||||
|
y.Mul(y, x)
|
||||||
|
}
|
||||||
|
|
||||||
|
return x.Set(y)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user