Пример #1
0
func (f rat) Evaluate(z complex128) complex128 {
	num := f.numerator.Evaluate(z)
	denom := f.denominator.Evaluate(z)
	if denom == 0 {
		return cmplx.Inf()
	}
	return num / denom
}
Пример #2
0
func BenchmarkComplex128DivDisInf(b *testing.B) {
	d := cmplx.Inf()
	n := 32 + 3i
	for i := 0; i < b.N; i++ {
		n += n / d
	}
	result = n
}
Пример #3
0
func BenchmarkComplex128DivNisInf(b *testing.B) {
	d := 15 + 2i
	n := cmplx.Inf()
	for i := 0; i < b.N; i++ {
		n += n / d
	}
	result = n
}
Пример #4
0
func BenchmarkComplex128DivNisInf(b *testing.B) {
	d := 15 + 2i
	n := cmplx.Inf()
	res := 0i
	for i := 0; i < b.N; i++ {
		d += 0.1i
		res += n / d
	}
	result = res
}
Пример #5
0
func main() {
	f := 3.2e5
	display(f)
	x := -7.3 - 8.9i
	display(x)
	y := complex64(-18.3 + 8.9i)
	display(y)
	z := complex(f, 13.2)
	display(z)
	display(real(y))
	display(imag(z))
	display(cmplx.Conj(z))
	display(cmplx.Inf())
	display(cmplx.NaN())
	display(cmplx.Sqrt(z))
}
Пример #6
0
func solve(equation Quadratic) Solutions {
	var solutions Solutions
	if EqualFloat(equation.a, 0) && EqualFloat(equation.b, 0) {
		solutions = append(solutions, Solution(cmplx.Inf()))
		return solutions
	}
	if EqualFloat(equation.a, 0) {
		solutions = append(solutions, Solution(complex(equation.c/equation.b, 0)))
		return solutions
	}
	a := complex(equation.a, 0)
	b := complex(equation.b, 0)
	c := complex(equation.c, 0)

	delta := cmplx.Sqrt(b*b - 4*a*c)
	x1 := (-b - delta) / 2 / a
	x2 := (-b + delta) / 2 / a

	solutions = append(solutions, Solution(x1))
	if !EqualComplex(x1, x2) {
		solutions = append(solutions, Solution(x2))
	}
	return solutions
}