Documentation
¶
Index ¶
- func PrecisionRequired(digits int) uint
- type Complex
- func (z *Complex) Abs() float64
- func (z *Complex) AbsSq() *big.Float
- func (z *Complex) Add(a, b *Complex) *Complex
- func (z *Complex) Complex128() complex128
- func (z *Complex) Copy(a *Complex) *Complex
- func (z *Complex) Div(a, b *Complex) *Complex
- func (z *Complex) Mul(a, b *Complex) *Complex
- func (z *Complex) Neg(a *Complex) *Complex
- func (z *Complex) Pow2(a *Complex) *Complex
- func (z *Complex) Prec() uint
- func (z *Complex) SetComplex128(c complex128) *Complex
- func (z *Complex) SetFloat64(real, imag float64) *Complex
- func (z *Complex) SetPrec(prec uint) *Complex
- func (z *Complex) SetString(real, imag string) *Complex
- func (z Complex) String() string
- func (z *Complex) Sub(a, b *Complex) *Complex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrecisionRequired ¶
PrecisionRequired determines the rough minimum number bits of precision to hold a n-digit number.
Types ¶
type Complex ¶
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 ¶
NewComplex returns a pointer to a complex number with the given real and imaginary parts, both with `prec` precision.
func (*Complex) Abs ¶
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 ¶
AbsSq returns the |z|^2, which is useful for performance critical work since it eliminates a call to Sqrt().
func (*Complex) Complex128 ¶
func (z *Complex) Complex128() complex128
Complex128 returns a `complex128`, with whatever precision losses happen from big.Float.Float64().
func (*Complex) Prec ¶
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 ¶
SetFloat64 sets the real and imaginary parts of the number to the parameters using the same rules as big.Float.SetFloat64().
func (*Complex) SetString ¶
SetString sets the real and imaginary components to the values of the string parameters using big.Float.Parse().