Example #1
0
func fibber(c chan *big.Int, out chan string, n int64) {
	// Keep the fibbers in dedicated operating system
	// threads, so that this program tests coordination
	// between pthreads and not just goroutines.
	runtime.LockOSThread()

	i := big.NewInt(n)
	if n == 0 {
		c <- i
	}
	for {
		j := <-c
		out <- j.String()
		i.Add(i, j)
		c <- i
	}
}
Example #2
0
File: pi.go Project: joninvski/go
 *
 * contributed by The Go Authors.
 * based on pidigits.c (by Paolo Bonzini & Sean Bartlett,
 *                      modified by Michael Mellor)
 */

package main

import (
	"fmt"
	big "gmp"
	"runtime"
)

var (
	tmp1  = big.NewInt(0)
	tmp2  = big.NewInt(0)
	numer = big.NewInt(1)
	accum = big.NewInt(0)
	denom = big.NewInt(1)
	ten   = big.NewInt(10)
)

func extractDigit() int64 {
	if big.CmpInt(numer, accum) > 0 {
		return -1
	}
	tmp1.Lsh(numer, 1).Add(tmp1, numer).Add(tmp1, accum)
	big.DivModInt(tmp1, tmp2, tmp1, denom)
	tmp2.Add(tmp2, numer)
	if big.CmpInt(tmp2, denom) >= 0 {