Commit f5e89c22 authored by Ian Lance Taylor's avatar Ian Lance Taylor Committed by Brad Fitzpatrick

Revert "math/cmplx: handle special cases"

This reverts CL 169501.

Reason for revert: The new tests fail at least on s390x and MIPS. This is likely a minor bug in the compiler or runtime. But this point in the release cycle is not the time to debug these details, which are unlikely to be new. Let's try again for 1.15.

Updates #29320
Fixes #35443

Change-Id: I2218b2083f8974b57d528e3742524393fc72b355
Reviewed-on: https://go-review.googlesource.com/c/go/+/206037
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent e038c7e4
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Package cmplx provides basic constants and mathematical functions for // Package cmplx provides basic constants and mathematical functions for
// complex numbers. Special case handling conforms to the C99 standard // complex numbers.
// Annex G IEC 60559-compatible complex arithmetic.
package cmplx package cmplx
import "math" import "math"
......
...@@ -49,31 +49,8 @@ import "math" ...@@ -49,31 +49,8 @@ import "math"
// Asin returns the inverse sine of x. // Asin returns the inverse sine of x.
func Asin(x complex128) complex128 { func Asin(x complex128) complex128 {
switch re, im := real(x), imag(x); { if imag(x) == 0 && math.Abs(real(x)) <= 1 {
case im == 0 && math.Abs(re) <= 1: return complex(math.Asin(real(x)), imag(x))
return complex(math.Asin(re), im)
case re == 0 && math.Abs(im) <= 1:
return complex(re, math.Asinh(im))
case math.IsNaN(im):
switch {
case re == 0:
return complex(re, math.NaN())
case math.IsInf(re, 0):
return complex(math.NaN(), re)
default:
return NaN()
}
case math.IsInf(im, 0):
switch {
case math.IsNaN(re):
return x
case math.IsInf(re, 0):
return complex(math.Copysign(math.Pi/4, re), im)
default:
return complex(math.Copysign(0, re), im)
}
case math.IsInf(re, 0):
return complex(math.Copysign(math.Pi/2, re), math.Copysign(re, im))
} }
ct := complex(-imag(x), real(x)) // i * x ct := complex(-imag(x), real(x)) // i * x
xx := x * x xx := x * x
...@@ -85,31 +62,8 @@ func Asin(x complex128) complex128 { ...@@ -85,31 +62,8 @@ func Asin(x complex128) complex128 {
// Asinh returns the inverse hyperbolic sine of x. // Asinh returns the inverse hyperbolic sine of x.
func Asinh(x complex128) complex128 { func Asinh(x complex128) complex128 {
switch re, im := real(x), imag(x); { if imag(x) == 0 && math.Abs(real(x)) <= 1 {
case im == 0 && math.Abs(re) <= 1: return complex(math.Asinh(real(x)), imag(x))
return complex(math.Asinh(re), im)
case re == 0 && math.Abs(im) <= 1:
return complex(re, math.Asin(im))
case math.IsInf(re, 0):
switch {
case math.IsInf(im, 0):
return complex(re, math.Copysign(math.Pi/4, im))
case math.IsNaN(im):
return x
default:
return complex(re, math.Copysign(0.0, im))
}
case math.IsNaN(re):
switch {
case im == 0:
return x
case math.IsInf(im, 0):
return complex(im, re)
default:
return NaN()
}
case math.IsInf(im, 0):
return complex(math.Copysign(im, re), math.Copysign(math.Pi/2, im))
} }
xx := x * x xx := x * x
x1 := complex(1+real(xx), imag(xx)) // 1 + x*x x1 := complex(1+real(xx), imag(xx)) // 1 + x*x
...@@ -137,9 +91,6 @@ func Acos(x complex128) complex128 { ...@@ -137,9 +91,6 @@ func Acos(x complex128) complex128 {
// Acosh returns the inverse hyperbolic cosine of x. // Acosh returns the inverse hyperbolic cosine of x.
func Acosh(x complex128) complex128 { func Acosh(x complex128) complex128 {
if x == 0 {
return complex(0, math.Copysign(math.Pi/2, imag(x)))
}
w := Acos(x) w := Acos(x)
if imag(w) <= 0 { if imag(w) <= 0 {
return complex(-imag(w), real(w)) // i * w return complex(-imag(w), real(w)) // i * w
...@@ -182,17 +133,6 @@ func Acosh(x complex128) complex128 { ...@@ -182,17 +133,6 @@ func Acosh(x complex128) complex128 {
// Atan returns the inverse tangent of x. // Atan returns the inverse tangent of x.
func Atan(x complex128) complex128 { func Atan(x complex128) complex128 {
switch re, im := real(x), imag(x); {
case im == 0:
return complex(math.Atan(re), im)
case re == 0 && math.Abs(im) <= 1:
return complex(re, math.Atanh(im))
case math.IsInf(im, 0) || math.IsInf(re, 0):
if math.IsNaN(re) {
return complex(math.NaN(), math.Copysign(0, im))
}
return complex(math.Copysign(math.Pi/2, re), math.Copysign(0, im))
}
x2 := real(x) * real(x) x2 := real(x) * real(x)
a := 1 - x2 - imag(x)*imag(x) a := 1 - x2 - imag(x)*imag(x)
if a == 0 { if a == 0 {
......
This diff is collapsed.
...@@ -49,23 +49,6 @@ import "math" ...@@ -49,23 +49,6 @@ import "math"
// Exp returns e**x, the base-e exponential of x. // Exp returns e**x, the base-e exponential of x.
func Exp(x complex128) complex128 { func Exp(x complex128) complex128 {
switch re, im := real(x), imag(x); {
case math.IsInf(re, 0):
switch {
case re > 0 && im == 0:
return x
case math.IsInf(im, 0) || math.IsNaN(im):
if re < 0 {
return complex(0, math.Copysign(0, im))
} else {
return complex(math.Inf(1.0), math.NaN())
}
}
case math.IsNaN(re):
if im == 0 {
return complex(math.NaN(), im)
}
}
r := math.Exp(real(x)) r := math.Exp(real(x))
s, c := math.Sincos(imag(x)) s, c := math.Sincos(imag(x))
return complex(r*c, r*s) return complex(r*c, r*s)
......
...@@ -60,6 +60,5 @@ func Log(x complex128) complex128 { ...@@ -60,6 +60,5 @@ func Log(x complex128) complex128 {
// Log10 returns the decimal logarithm of x. // Log10 returns the decimal logarithm of x.
func Log10(x complex128) complex128 { func Log10(x complex128) complex128 {
z := Log(x) return math.Log10E * Log(x)
return complex(math.Log10E*real(z), math.Log10E*imag(z))
} }
...@@ -51,19 +51,6 @@ import "math" ...@@ -51,19 +51,6 @@ import "math"
// Sin returns the sine of x. // Sin returns the sine of x.
func Sin(x complex128) complex128 { func Sin(x complex128) complex128 {
switch re, im := real(x), imag(x); {
case im == 0 && (math.IsInf(re, 0) || math.IsNaN(re)):
return complex(math.NaN(), im)
case math.IsInf(im, 0):
switch {
case re == 0:
return x
case math.IsInf(re, 0) || math.IsNaN(re):
return complex(math.NaN(), im)
}
case re == 0 && math.IsNaN(im):
return x
}
s, c := math.Sincos(real(x)) s, c := math.Sincos(real(x))
sh, ch := sinhcosh(imag(x)) sh, ch := sinhcosh(imag(x))
return complex(s*ch, c*sh) return complex(s*ch, c*sh)
...@@ -84,19 +71,6 @@ func Sin(x complex128) complex128 { ...@@ -84,19 +71,6 @@ func Sin(x complex128) complex128 {
// Sinh returns the hyperbolic sine of x. // Sinh returns the hyperbolic sine of x.
func Sinh(x complex128) complex128 { func Sinh(x complex128) complex128 {
switch re, im := real(x), imag(x); {
case re == 0 && (math.IsInf(im, 0) || math.IsNaN(im)):
return complex(re, math.NaN())
case math.IsInf(re, 0):
switch {
case im == 0:
return complex(re, im)
case math.IsInf(im, 0) || math.IsNaN(im):
return complex(re, math.NaN())
}
case im == 0 && math.IsNaN(re):
return complex(math.NaN(), im)
}
s, c := math.Sincos(imag(x)) s, c := math.Sincos(imag(x))
sh, ch := sinhcosh(real(x)) sh, ch := sinhcosh(real(x))
return complex(c*sh, s*ch) return complex(c*sh, s*ch)
...@@ -122,19 +96,6 @@ func Sinh(x complex128) complex128 { ...@@ -122,19 +96,6 @@ func Sinh(x complex128) complex128 {
// Cos returns the cosine of x. // Cos returns the cosine of x.
func Cos(x complex128) complex128 { func Cos(x complex128) complex128 {
switch re, im := real(x), imag(x); {
case im == 0 && (math.IsInf(re, 0) || math.IsNaN(re)):
return complex(math.NaN(), -im*math.Copysign(0, re))
case math.IsInf(im, 0):
switch {
case re == 0:
return complex(math.Inf(1), -re*math.Copysign(0, im))
case math.IsInf(re, 0) || math.IsNaN(re):
return complex(math.Inf(1), math.NaN())
}
case re == 0 && math.IsNaN(im):
return complex(math.NaN(), 0)
}
s, c := math.Sincos(real(x)) s, c := math.Sincos(real(x))
sh, ch := sinhcosh(imag(x)) sh, ch := sinhcosh(imag(x))
return complex(c*ch, -s*sh) return complex(c*ch, -s*sh)
...@@ -154,19 +115,6 @@ func Cos(x complex128) complex128 { ...@@ -154,19 +115,6 @@ func Cos(x complex128) complex128 {
// Cosh returns the hyperbolic cosine of x. // Cosh returns the hyperbolic cosine of x.
func Cosh(x complex128) complex128 { func Cosh(x complex128) complex128 {
switch re, im := real(x), imag(x); {
case re == 0 && (math.IsInf(im, 0) || math.IsNaN(im)):
return complex(math.NaN(), re*math.Copysign(0, im))
case math.IsInf(re, 0):
switch {
case im == 0:
return complex(math.Inf(1), im*math.Copysign(0, re))
case math.IsInf(im, 0) || math.IsNaN(im):
return complex(math.Inf(1), math.NaN())
}
case im == 0 && math.IsNaN(re):
return complex(math.NaN(), im)
}
s, c := math.Sincos(imag(x)) s, c := math.Sincos(imag(x))
sh, ch := sinhcosh(real(x)) sh, ch := sinhcosh(real(x))
return complex(c*ch, s*sh) return complex(c*ch, s*sh)
......
...@@ -65,8 +65,6 @@ func Sqrt(x complex128) complex128 { ...@@ -65,8 +65,6 @@ func Sqrt(x complex128) complex128 {
return complex(0, math.Copysign(math.Sqrt(-real(x)), imag(x))) return complex(0, math.Copysign(math.Sqrt(-real(x)), imag(x)))
} }
return complex(math.Sqrt(real(x)), imag(x)) return complex(math.Sqrt(real(x)), imag(x))
} else if math.IsInf(imag(x), 0) {
return complex(math.Inf(1.0), imag(x))
} }
if real(x) == 0 { if real(x) == 0 {
if imag(x) < 0 { if imag(x) < 0 {
......
...@@ -57,16 +57,6 @@ import "math" ...@@ -57,16 +57,6 @@ import "math"
// Tan returns the tangent of x. // Tan returns the tangent of x.
func Tan(x complex128) complex128 { func Tan(x complex128) complex128 {
switch re, im := real(x), imag(x); {
case math.IsInf(im, 0):
switch {
case math.IsInf(re, 0) || math.IsNaN(re):
return complex(math.Copysign(0, re), math.Copysign(1, im))
}
return complex(math.Copysign(0, math.Sin(2*re)), math.Copysign(1, im))
case re == 0 && math.IsNaN(im):
return x
}
d := math.Cos(2*real(x)) + math.Cosh(2*imag(x)) d := math.Cos(2*real(x)) + math.Cosh(2*imag(x))
if math.Abs(d) < 0.25 { if math.Abs(d) < 0.25 {
d = tanSeries(x) d = tanSeries(x)
...@@ -91,16 +81,6 @@ func Tan(x complex128) complex128 { ...@@ -91,16 +81,6 @@ func Tan(x complex128) complex128 {
// Tanh returns the hyperbolic tangent of x. // Tanh returns the hyperbolic tangent of x.
func Tanh(x complex128) complex128 { func Tanh(x complex128) complex128 {
switch re, im := real(x), imag(x); {
case math.IsInf(re, 0):
switch {
case math.IsInf(im, 0) || math.IsNaN(im):
return complex(math.Copysign(1, re), math.Copysign(0, im))
}
return complex(math.Copysign(1, re), math.Copysign(0, math.Sin(2*im)))
case im == 0 && math.IsNaN(re):
return x
}
d := math.Cosh(2*real(x)) + math.Cos(2*imag(x)) d := math.Cosh(2*real(x)) + math.Cos(2*imag(x))
if d == 0 { if d == 0 {
return Inf() return Inf()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment