package module
Version: v0.0.0-...-5277802 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 2 Imported by: 1



PiHex Library generates a hexadecimal number sequence in the number Pi in the range from 0 to 1.0e10000000. To calculate using "Bailey-Borwein-Plouffe" algorithm, instructions that was published by David H. Bailey September 17, 2006.

API documentation Go Report Card Mentioned in Awesome Go


An example of using the PiHex Library:

package main

import (

func main() {
	pi := PiHex.New()
	fmt.Print("The first 9 digits of Pi (hexadecimal): ", pi.Get(0, 9))


In the configuration file, you can change the constant STEP. This constant determines the amount generated in one step numbers. The reduction leads to a constant increase in the operating time of the program.

Attention! This constant can not be more than 9! Limitation due to the 64-bit library architecture.

The configuration file config.go


To optimize the run-time program, highly loaded sections of the library are performed in parallel (4 goroutines).



  • New - create a new PiHex
  • Get - receiving a sequence of hexadecimal digits starting at the specified position and in the right quantity.


pi := PiHex.New()
x :=  pi.Get(1000, 5)


The Bailey–Borwein–Plouffe formula (BBP formula) is a spigot algorithm for computing the nth binary digit of Pi using base 16 math. The formula can directly calculate the value of any given digit of π without calculating the preceding digits. The BBP is a summation-style formula that was discovered in 1995 by Simon Plouffe and was named after the authors of the paper in which the formula was published, David H. Bailey, Peter Borwein, and Simon Plouffe.


Plays Library is based on the publication "The BBP Algorithm for Pi" of David H. Bailey on September 17, 2006: http://www.davidhbailey.com/dhbpapers/bbp-alg.pdf

Copyright © 2017-2020 Eduard Sesigin. All rights reserved. Contacts: claygod@yandex.ru




View Source
const (
	// The limit for calculation
	CLIMIT = 10000000
	// The number of digits exponent
	NTP = 25
	// Special option
	EPS = 1e-17

Non-editable parameters

View Source
const (
	// The number of hexadecimal digits generated in one step.
	// For 64-bit architecture can not exceed nine.
	// If you have doubts about the accuracy, you can reduce this number
	// (it's a bit to increase the work program).
	STEP = 9 // or 8

Editable parameters


This section is empty.


This section is empty.


type Pi

type Pi struct {
	// contains filtered or unexported fields

Pi structure

func New

func New() *Pi

New - create a new PiHex-struct

func (*Pi) Get

func (pi *Pi) Get(start int, num int) []byte

Get - 'num' hexadecimal digits in the number Pi since 'start' position. If the inputs exceed the permissible values, it returns an empty slice.


start - start number num - how to calculate the numbers


slice bytes 0 to 15

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto