diff options
Diffstat (limited to 'libgo/go/math/cmplx')
-rw-r--r-- | libgo/go/math/cmplx/cmath_test.go | 8 | ||||
-rw-r--r-- | libgo/go/math/cmplx/example_test.go | 30 | ||||
-rw-r--r-- | libgo/go/math/cmplx/tan.go | 12 |
3 files changed, 45 insertions, 5 deletions
diff --git a/libgo/go/math/cmplx/cmath_test.go b/libgo/go/math/cmplx/cmath_test.go index d904be8..7a5c485 100644 --- a/libgo/go/math/cmplx/cmath_test.go +++ b/libgo/go/math/cmplx/cmath_test.go @@ -759,6 +759,14 @@ func TestTanh(t *testing.T) { } } +// See issue 17577 +func TestInfiniteLoopIntanSeries(t *testing.T) { + want := Inf() + if got := Cot(0); got != want { + t.Errorf("Cot(0): got %g, want %g", got, want) + } +} + func BenchmarkAbs(b *testing.B) { for i := 0; i < b.N; i++ { Abs(complex(2.5, 3.5)) diff --git a/libgo/go/math/cmplx/example_test.go b/libgo/go/math/cmplx/example_test.go new file mode 100644 index 0000000..be87cff --- /dev/null +++ b/libgo/go/math/cmplx/example_test.go @@ -0,0 +1,30 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build ignore + +package cmplx_test + +import ( + "fmt" + "math" + "math/cmplx" +) + +func ExampleAbs() { + fmt.Printf("%.1f", cmplx.Abs(3+4i)) + // Output: 5.0 +} + +// ExampleExp computes Euler's identity. +func ExampleExp() { + fmt.Printf("%.1f", cmplx.Exp(1i*math.Pi)+1) + // Output: (0.0+0.0i) +} + +func ExamplePolar() { + r, theta := cmplx.Polar(2i) + fmt.Printf("r: %.1f, θ: %.1f*π", r, theta/math.Pi) + // Output: r: 2.0, θ: 0.5*π +} diff --git a/libgo/go/math/cmplx/tan.go b/libgo/go/math/cmplx/tan.go index 9485315..2990552 100644 --- a/libgo/go/math/cmplx/tan.go +++ b/libgo/go/math/cmplx/tan.go @@ -120,9 +120,9 @@ func tanSeries(z complex128) float64 { rn := 0.0 d := 0.0 for { - rn += 1 + rn++ f *= rn - rn += 1 + rn++ f *= rn x2 *= x y2 *= y @@ -130,16 +130,18 @@ func tanSeries(z complex128) float64 { t /= f d += t - rn += 1 + rn++ f *= rn - rn += 1 + rn++ f *= rn x2 *= x y2 *= y t = y2 - x2 t /= f d += t - if math.Abs(t/d) <= MACHEP { + if !(math.Abs(t/d) > MACHEP) { + // Caution: Use ! and > instead of <= for correct behavior if t/d is NaN. + // See issue 17577. break } } |