big

package
v0.0.0-...-ff93628 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2018 License: Unlicense Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrecisionRequired

func PrecisionRequired(digits int) uint

PrecisionRequired determines the rough minimum number bits of precision to hold a n-digit number.

Types

type Complex

type Complex struct {
	R big.Float
	I big.Float
}

Complex represents a complex number with arbitrary precision. It uses 2 big.Float types, one `R` for the real part and one `I` for the imaginary part.

Instantiation can be performed in the usual ways.

c1 := NewComplex(1.0,-10.25, 128) // 128 bits of precision
c2 := new(Complex) // default big.Float precision of 0
c3 := Complex{} // default big.Float precision of 0
var c4 Complex // default big.Float precision of 0

Mathmatical operations generally follow the conventions of the standard library's `big` package. Notable exceptions are the Abs() and AbsSq() functions.

The type's string representation mostly matches the built-in complex64 and complex128's format, except that there is ALWAYS a '+' between the real and imaginary components. For example, the built-in shows

(1.5-2.75i)

for number with a negative imaginary part, whereas Complex will show

(1.5+-2.75i)

func NewComplex

func NewComplex(real, imag float64, prec uint) *Complex

NewComplex returns a pointer to a complex number with the given real and imaginary parts, both with `prec` precision.

func (*Complex) Abs

func (z *Complex) Abs() float64

Abs returns the absolute value of z, |z|. The conversion to float64 may introduce error, but is necessary to use math.Sqrt(float64) since big.Float presently lacks a Sqrt() method (until Go v1.10?).

func (*Complex) AbsSq

func (z *Complex) AbsSq() *big.Float

AbsSq returns the |z|^2, which is useful for performance critical work since it eliminates a call to Sqrt().

func (*Complex) Add

func (z *Complex) Add(a, b *Complex) *Complex

Add adds a and b and stores the result in z.

func (*Complex) Complex128

func (z *Complex) Complex128() complex128

Complex128 returns a `complex128`, with whatever precision losses happen from big.Float.Float64().

func (*Complex) Copy

func (z *Complex) Copy(a *Complex) *Complex

Copy will copy a's value, precision, etc into z unless z==a.

func (*Complex) Div

func (z *Complex) Div(a, b *Complex) *Complex

Div divides a by b and stores the result in z.

func (*Complex) Mul

func (z *Complex) Mul(a, b *Complex) *Complex

Mul multiplies a and b and stores the result in z.

func (*Complex) Neg

func (z *Complex) Neg(a *Complex) *Complex

Neg negates a and stores the result in z.

func (*Complex) Pow2

func (z *Complex) Pow2(a *Complex) *Complex

Pow2 squares a and stores the result in z. This is just Mul(a,a).

func (*Complex) Prec

func (z *Complex) Prec() uint

Prec returns the lower of R.Prec() and I.Prec().

Although probably not usual, R and I's precision may be set independently.

func (*Complex) SetComplex128

func (z *Complex) SetComplex128(c complex128) *Complex

SetComplex128 sets the real and imaginary compontents equal to those of the parameter, using the rules of SetFloat64().

func (*Complex) SetFloat64

func (z *Complex) SetFloat64(real, imag float64) *Complex

SetFloat64 sets the real and imaginary parts of the number to the parameters using the same rules as big.Float.SetFloat64().

func (*Complex) SetPrec

func (z *Complex) SetPrec(prec uint) *Complex

SetPrec sets both R and I's precisions to `prec`.

func (*Complex) SetString

func (z *Complex) SetString(real, imag string) *Complex

SetString sets the real and imaginary components to the values of the string parameters using big.Float.Parse().

func (Complex) String

func (z Complex) String() string

String returns a string representation of the complex number.

See type documentation for other details.

func (*Complex) Sub

func (z *Complex) Sub(a, b *Complex) *Complex

Sub subtracts b from a and stores the result in z.

Jump to

Keyboard shortcuts

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