Skip to content

Instantly share code, notes, and snippets.

@0xkohe
Created August 10, 2020 10:36
Show Gist options
  • Save 0xkohe/2704104a6cb796fd376c948fe21118c5 to your computer and use it in GitHub Desktop.
Save 0xkohe/2704104a6cb796fd376c948fe21118c5 to your computer and use it in GitHub Desktop.
func calcFib(n int) *big.Int {
// (1+√5)/2
a := big.NewRat(1, 2)
b := big.NewRat(1, 2)
x := fibNum{a, b}
// (1-√5)/2
c := big.NewRat(1, 2)
d := big.NewRat(-1, 2)
y := fibNum{c, d}
// (1/√5)
e := big.NewRat(0, 999)
f := big.NewRat(1, 5)
z := fibNum{e, f}
tmp := fibMin(fibExp(x, n), fibExp(y, n))
// *(1/√5)
r := fibMul(tmp, z)
return r.num.Num()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment