bigfloat

package module
Version: v0.0.0-...-b176f1e Latest Latest
Warning

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

Go to latest
Published: May 6, 2018 License: MIT Imports: 2 Imported by: 0

README

Floats

Package bigfloat provides the implementation of a few additional operations (square root, exponentiation, natural logarithm, exponential function) for the standard library big.Float type.

GoDoc

Install

go get github.com/ALTree/bigfloat

Please note that bigfloat requires Go >= 1.5 (since the big.Float type is not available in previous versions).

Example

package main

import (
	"fmt"
	"math/big"

	"github.com/ALTree/bigfloat"
)

// In this example, we'll compute the value of the
// trascendental number 2 ** √2, also known as
// the Gelfond–Schneider constant, to 1000 bits.
func main() {
	// Work with 1000 binary digits of precision.
	const prec = 1000

	two := big.NewFloat(2).SetPrec(prec)

	// Compute √2.
	// Sqrt uses the argument's precision.
	sqrtTwo := bigfloat.Sqrt(two)

	// Compute 2 ** √2
	// Pow uses the first argument's precision.
	gsc := bigfloat.Pow(two, sqrtTwo)

	// Print gsc, truncated to 60 decimal digits.
	fmt.Printf("gsc = %.60f...\n", gsc)
}

outputs

gsc = 2.665144142690225188650297249873139848274211313714659492835980...

Documentation

See https://godoc.org/github.com/ALTree/bigfloat

Documentation

Overview

Package bigfloat provides the implementation of a few additional operations for the standard library big.Float type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exp

func Exp(z *big.Float) *big.Float

Exp returns a big.Float representation of exp(z). Precision is the same as the one of the argument. The function returns +Inf when z = +Inf, and 0 when z = -Inf.

func Log

func Log(z *big.Float) *big.Float

Log returns a big.Float representation of the natural logarithm of z. Precision is the same as the one of the argument. The function panics if z is negative, returns -Inf when z = 0, and +Inf when z = +Inf

func Pow

func Pow(z *big.Float, w *big.Float) *big.Float

Pow returns a big.Float representation of z**w. Precision is the same as the one of the first argument. The function panics when z is negative.

func Sqrt

func Sqrt(z *big.Float) *big.Float

Sqrt returns a big.Float representation of the square root of z. Precision is the same as the one of the argument. The function panics if z is negative, returns ±0 when z = ±0, and +Inf when z = +Inf.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL