-
Notifications
You must be signed in to change notification settings - Fork 0
/
pi.go
26 lines (23 loc) · 1.04 KB
/
pi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main
import "math/big"
// Pi to 1018-bit precision
var piBytes = []byte{
0x03, 0x24, 0x3f, 0x6a, 0x88, 0x85, 0xa3, 0x08, 0xd3, 0x13, 0x19, 0x8a, 0x2e, 0x03,
0x70, 0x73, 0x44, 0xa4, 0x09, 0x38, 0x22, 0x29, 0x9f, 0x31, 0xd0, 0x08, 0x2e, 0xfa,
0x98, 0xec, 0x4e, 0x6c, 0x89, 0x45, 0x28, 0x21, 0xe6, 0x38, 0xd0, 0x13, 0x77, 0xbe,
0x54, 0x66, 0xcf, 0x34, 0xe9, 0x0c, 0x6c, 0xc0, 0xac, 0x29, 0xb7, 0xc9, 0x7c, 0x50,
0xdd, 0x3f, 0x84, 0xd5, 0xb5, 0xb5, 0x47, 0x09, 0x17, 0x92, 0x16, 0xd5, 0xd9, 0x89,
0x79, 0xfb, 0x1b, 0xd1, 0x31, 0x0b, 0xa6, 0x98, 0xdf, 0xb5, 0xac, 0x2f, 0xfd, 0x72,
0xdb, 0xd0, 0x1a, 0xdf, 0xb7, 0xb8, 0xe1, 0xaf, 0xed, 0x6a, 0x26, 0x7e, 0x96, 0xba,
0x7c, 0x90, 0x45, 0xf1, 0x2c, 0x7f, 0x99, 0x24, 0xa1, 0x99, 0x47, 0xb3, 0x91, 0x6c,
0xf7, 0x08, 0x01, 0xf2, 0xe2, 0x85, 0x8e, 0xfc, 0x16, 0x63, 0x69, 0x20, 0xd8, 0x71,
0x57, 0x4e,
}
// RatPi returns pi as a Rat with a *lot* of precision
func RatPi(pi *big.Rat) {
var num big.Int
var den big.Int
num.SetBytes(piBytes)
den.SetBit(&den, (len(piBytes)-1)*8, 1)
pi.SetFrac(&num, &den)
}