func next_term(k int64) { y2 := k*2 + 1 tmp1 = numer.Shl(1) bignum.Iadd(accum, accum, tmp1) bignum.Iscale(accum, y2) bignum.Iscale(numer, k) bignum.Iscale(denom, y2) }
func extract_digit() int64 { if numer.Cmp(accum) > 0 { return -1 } // Compute (numer * 3 + accum) / denom tmp1 = numer.Shl(1) bignum.Iadd(tmp1, tmp1, numer) bignum.Iadd(tmp1, tmp1, accum) tmp1, tmp2 := tmp1.QuoRem(denom) // Now, if (numer * 4 + accum) % denom... bignum.Iadd(tmp2, tmp2, numer) // ... is normalized, then the two divisions have the same result. if tmp2.Cmp(denom) >= 0 { return -1 } return tmp1.Value() }