mirror of
https://github.com/golang/go
synced 2024-11-23 00:20:12 -07:00
75a38963ca
better FFI demo: compute fibonacci numbers using FFI'ed libgmp. R=r DELTA=281 (255 added, 19 deleted, 7 changed) OCL=33815 CL=33820
29 lines
444 B
Go
29 lines
444 B
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
package main
|
|
|
|
import big "gmp"
|
|
//import "big"
|
|
import "fmt"
|
|
|
|
func Fib(n int) *big.Int {
|
|
a := big.NewInt(0);
|
|
b := big.NewInt(1);
|
|
|
|
for i := 0; i < n; i++ {
|
|
a, b = b, a;
|
|
b.Add(a, b);
|
|
}
|
|
|
|
return b;
|
|
}
|
|
|
|
func main() {
|
|
for i := 0; i <= 100; i++ {
|
|
fmt.Println(5*i, Fib(5*i));
|
|
}
|
|
}
|