Skip to content
PiHex Library, written in Go, generates a hexadecimal number sequence in the number Pi in the range from 0 to 10,000,000.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE.md Update LICENSE.md Apr 30, 2019
README.md Update README.md Apr 16, 2019
ph_api.go Update ph_api.go May 5, 2019
ph_config.go Update ph_config.go May 24, 2019
ph_test.go
ph_work.go

README.md

PiHex

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

API documentation Go Report Card

Usage

An example of using the PiHex Library:

package main

import (
	"fmt"
	"github.com/claygod/PiHex"
)

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

Settings

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

Perfomance

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

API

Methods:

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

Example:

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

Algorithm

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.

Implementation

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-2019 Eduard Sesigin. All rights reserved. Contacts: claygod@yandex.ru

You can’t perform that action at this time.