bigcomplex

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigComplex

type BigComplex struct {
	Real *big.Float
	Imag *big.Float
}

func Add

func Add(bcs ...*BigComplex) *BigComplex

func Cube

func Cube(a *BigComplex) *BigComplex

func Div

func Div(bc1, bc2 *BigComplex) *BigComplex

func FromInt

func FromInt(i int) *BigComplex

func Mul

func Mul(bcs ...*BigComplex) *BigComplex

func Product

func Product(a, b *BigComplex) *BigComplex

func Sq

func Sq(a *BigComplex) *BigComplex

func Sub

func Sub(a, b *BigComplex) *BigComplex

func Unique

func Unique(in []*BigComplex) []*BigComplex

func (*BigComplex) Cbrt

func (bc *BigComplex) Cbrt() *BigComplex

func (*BigComplex) Complex128

func (bc *BigComplex) Complex128() complex128

func (*BigComplex) Equals

func (bc *BigComplex) Equals(other *BigComplex) bool

func (*BigComplex) IsZero

func (bc *BigComplex) IsZero() bool

func (*BigComplex) Magnitude

func (bc *BigComplex) Magnitude() *big.Float

func (*BigComplex) Pow

func (bc *BigComplex) Pow(e *big.Float) *BigComplex

func (*BigComplex) Sqrt

func (bc *BigComplex) Sqrt() *BigComplex
On it's face this is likely wrong - it occasionally produces 4 roots!!!

// Uses a simplified version of this code // https://www.geeksforgeeks.org/square-root-of-two-complex-numbers/

func (bc *BigComplex) Sqrt() []*BigComplex {
	result := []*BigComplex{}
	a := bc.Real
	b := bc.Imag
	two := fromInt(2)
	negOne := fromInt(-1)
	magSq := add(sq(a), sq(b))
	x1 := abs(sqrtSimple(div(add(a, sqrtSimple(magSq)), two)))
	if isZero(x1) {
		y1 := sqrtSimple(mul(fromInt(-1), a))
		result = append(result, &BigComplex{Real: x1, Imag: y1})
	} else {
		y1 := div(b, mul(two, x1))
		result = append(result, &BigComplex{Real: x1, Imag: y1})
		x2 := mul(negOne, x1)
		y2 := div(b, mul(two, x2))
		result = append(result, &BigComplex{Real: x2, Imag: y2})
	}

	x3 := div(sub(a, sqrtSimple(magSq)), two)
	if positive(x3) {
		x3 = abs(sqrtSimple(x3))
		y3 := div(b, mul(two, x3))
		result = append(result, &BigComplex{Real: x3, Imag: y3})
		x4 := mul(negOne, x3)
		y4 := div(b, mul(two, x3))
		result = append(result, &BigComplex{Real: x4, Imag: y4})
	}
	return result
}

func (*BigComplex) Theta

func (bc *BigComplex) Theta() *big.Float

Jump to

Keyboard shortcuts

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