diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-02-14 13:23:51 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-02-14 13:23:51 +0100 |
commit | 758ff64c69e34965f8af5b2d6ffd65e8d7ab2150 (patch) | |
tree | 6d6b34f8c678862fe9b56c945a7b63f68502c245 /src/pkg/cmath | |
parent | 3e45412327a2654a77944249962b3652e6142299 (diff) | |
download | golang-upstream/2011-02-01.1.tar.gz |
Imported Upstream version 2011-02-01.1upstream/2011-02-01.1
Diffstat (limited to 'src/pkg/cmath')
-rw-r--r-- | src/pkg/cmath/asin.go | 32 | ||||
-rw-r--r-- | src/pkg/cmath/cmath_test.go | 64 | ||||
-rw-r--r-- | src/pkg/cmath/conj.go | 2 | ||||
-rw-r--r-- | src/pkg/cmath/exp.go | 2 | ||||
-rw-r--r-- | src/pkg/cmath/isinf.go | 4 | ||||
-rw-r--r-- | src/pkg/cmath/isnan.go | 2 | ||||
-rw-r--r-- | src/pkg/cmath/log.go | 2 | ||||
-rw-r--r-- | src/pkg/cmath/pow.go | 4 | ||||
-rw-r--r-- | src/pkg/cmath/rect.go | 2 | ||||
-rw-r--r-- | src/pkg/cmath/sin.go | 8 | ||||
-rw-r--r-- | src/pkg/cmath/sqrt.go | 14 | ||||
-rw-r--r-- | src/pkg/cmath/tan.go | 16 |
12 files changed, 76 insertions, 76 deletions
diff --git a/src/pkg/cmath/asin.go b/src/pkg/cmath/asin.go index eb87ba5e5..d6a3ca480 100644 --- a/src/pkg/cmath/asin.go +++ b/src/pkg/cmath/asin.go @@ -51,16 +51,16 @@ import "math" func Asin(x complex128) complex128 { if imag(x) == 0 { if math.Fabs(real(x)) > 1 { - return cmplx(math.Pi/2, 0) // DOMAIN error + return complex(math.Pi/2, 0) // DOMAIN error } - return cmplx(math.Asin(real(x)), 0) + return complex(math.Asin(real(x)), 0) } - ct := cmplx(-imag(x), real(x)) // i * x + ct := complex(-imag(x), real(x)) // i * x xx := x * x - x1 := cmplx(1-real(xx), -imag(xx)) // 1 - x*x - x2 := Sqrt(x1) // x2 = sqrt(1 - x*x) + x1 := complex(1-real(xx), -imag(xx)) // 1 - x*x + x2 := Sqrt(x1) // x2 = sqrt(1 - x*x) w := Log(ct + x2) - return cmplx(imag(w), -real(w)) // -i * w + return complex(imag(w), -real(w)) // -i * w } // Asinh returns the inverse hyperbolic sine of x. @@ -68,13 +68,13 @@ func Asinh(x complex128) complex128 { // TODO check range if imag(x) == 0 { if math.Fabs(real(x)) > 1 { - return cmplx(math.Pi/2, 0) // DOMAIN error + return complex(math.Pi/2, 0) // DOMAIN error } - return cmplx(math.Asinh(real(x)), 0) + return complex(math.Asinh(real(x)), 0) } xx := x * x - x1 := cmplx(1+real(xx), imag(xx)) // 1 + x*x - return Log(x + Sqrt(x1)) // log(x + sqrt(1 + x*x)) + x1 := complex(1+real(xx), imag(xx)) // 1 + x*x + return Log(x + Sqrt(x1)) // log(x + sqrt(1 + x*x)) } // Complex circular arc cosine @@ -93,16 +93,16 @@ func Asinh(x complex128) complex128 { // Acos returns the inverse cosine of x. func Acos(x complex128) complex128 { w := Asin(x) - return cmplx(math.Pi/2-real(w), -imag(w)) + return complex(math.Pi/2-real(w), -imag(w)) } // Acosh returns the inverse hyperbolic cosine of x. func Acosh(x complex128) complex128 { w := Acos(x) if imag(w) <= 0 { - return cmplx(-imag(w), real(w)) // i * w + return complex(-imag(w), real(w)) // i * w } - return cmplx(imag(w), -real(w)) // -i * w + return complex(imag(w), -real(w)) // -i * w } // Complex circular arc tangent @@ -159,12 +159,12 @@ func Atan(x complex128) complex128 { } t = imag(x) + 1 c := (x2 + t*t) / b - return cmplx(w, 0.25*math.Log(c)) + return complex(w, 0.25*math.Log(c)) } // Atanh returns the inverse hyperbolic tangent of x. func Atanh(x complex128) complex128 { - z := cmplx(-imag(x), real(x)) // z = i * x + z := complex(-imag(x), real(x)) // z = i * x z = Atan(z) - return cmplx(imag(z), -real(z)) // z = -i * z + return complex(imag(z), -real(z)) // z = -i * z } diff --git a/src/pkg/cmath/cmath_test.go b/src/pkg/cmath/cmath_test.go index 93fac4e20..6a595b0a6 100644 --- a/src/pkg/cmath/cmath_test.go +++ b/src/pkg/cmath/cmath_test.go @@ -355,15 +355,15 @@ var expSC = []complex128{ NaN(), } var vcIsNaNSC = []complex128{ - cmplx(math.Inf(-1), math.Inf(-1)), - cmplx(math.Inf(-1), math.NaN()), - cmplx(math.NaN(), math.Inf(-1)), - cmplx(0, math.NaN()), - cmplx(math.NaN(), 0), - cmplx(math.Inf(1), math.Inf(1)), - cmplx(math.Inf(1), math.NaN()), - cmplx(math.NaN(), math.Inf(1)), - cmplx(math.NaN(), math.NaN()), + complex(math.Inf(-1), math.Inf(-1)), + complex(math.Inf(-1), math.NaN()), + complex(math.NaN(), math.Inf(-1)), + complex(0, math.NaN()), + complex(math.NaN(), 0), + complex(math.Inf(1), math.Inf(1)), + complex(math.Inf(1), math.NaN()), + complex(math.NaN(), math.Inf(1)), + complex(math.NaN(), math.NaN()), } var isNaNSC = []bool{ false, @@ -615,7 +615,7 @@ func TestExp(t *testing.T) { func TestIsNaN(t *testing.T) { for i := 0; i < len(vcIsNaNSC); i++ { if f := IsNaN(vcIsNaNSC[i]); isNaNSC[i] != f { - t.Errorf("IsNaN(%g) = %g, want %g", vcIsNaNSC[i], f, isNaNSC[i]) + t.Errorf("IsNaN(%v) = %v, want %v", vcIsNaNSC[i], f, isNaNSC[i]) } } } @@ -656,7 +656,7 @@ func TestPolar(t *testing.T) { } } func TestPow(t *testing.T) { - var a = cmplx(float64(3), float64(3)) + var a = complex(3.0, 3.0) for i := 0; i < len(vc); i++ { if f := Pow(a, vc[i]); !cSoclose(pow[i], f, 4e-15) { t.Errorf("Pow(%g, %g) = %g, want %g", a, vc[i], f, pow[i]) @@ -743,82 +743,82 @@ func TestTanh(t *testing.T) { func BenchmarkAbs(b *testing.B) { for i := 0; i < b.N; i++ { - Abs(cmplx(2.5, 3.5)) + Abs(complex(2.5, 3.5)) } } func BenchmarkAcos(b *testing.B) { for i := 0; i < b.N; i++ { - Acos(cmplx(2.5, 3.5)) + Acos(complex(2.5, 3.5)) } } func BenchmarkAcosh(b *testing.B) { for i := 0; i < b.N; i++ { - Acosh(cmplx(2.5, 3.5)) + Acosh(complex(2.5, 3.5)) } } func BenchmarkAsin(b *testing.B) { for i := 0; i < b.N; i++ { - Asin(cmplx(2.5, 3.5)) + Asin(complex(2.5, 3.5)) } } func BenchmarkAsinh(b *testing.B) { for i := 0; i < b.N; i++ { - Asinh(cmplx(2.5, 3.5)) + Asinh(complex(2.5, 3.5)) } } func BenchmarkAtan(b *testing.B) { for i := 0; i < b.N; i++ { - Atan(cmplx(2.5, 3.5)) + Atan(complex(2.5, 3.5)) } } func BenchmarkAtanh(b *testing.B) { for i := 0; i < b.N; i++ { - Atanh(cmplx(2.5, 3.5)) + Atanh(complex(2.5, 3.5)) } } func BenchmarkConj(b *testing.B) { for i := 0; i < b.N; i++ { - Conj(cmplx(2.5, 3.5)) + Conj(complex(2.5, 3.5)) } } func BenchmarkCos(b *testing.B) { for i := 0; i < b.N; i++ { - Cos(cmplx(2.5, 3.5)) + Cos(complex(2.5, 3.5)) } } func BenchmarkCosh(b *testing.B) { for i := 0; i < b.N; i++ { - Cosh(cmplx(2.5, 3.5)) + Cosh(complex(2.5, 3.5)) } } func BenchmarkExp(b *testing.B) { for i := 0; i < b.N; i++ { - Exp(cmplx(2.5, 3.5)) + Exp(complex(2.5, 3.5)) } } func BenchmarkLog(b *testing.B) { for i := 0; i < b.N; i++ { - Log(cmplx(2.5, 3.5)) + Log(complex(2.5, 3.5)) } } func BenchmarkLog10(b *testing.B) { for i := 0; i < b.N; i++ { - Log10(cmplx(2.5, 3.5)) + Log10(complex(2.5, 3.5)) } } func BenchmarkPhase(b *testing.B) { for i := 0; i < b.N; i++ { - Phase(cmplx(2.5, 3.5)) + Phase(complex(2.5, 3.5)) } } func BenchmarkPolar(b *testing.B) { for i := 0; i < b.N; i++ { - Polar(cmplx(2.5, 3.5)) + Polar(complex(2.5, 3.5)) } } func BenchmarkPow(b *testing.B) { for i := 0; i < b.N; i++ { - Pow(cmplx(2.5, 3.5), cmplx(2.5, 3.5)) + Pow(complex(2.5, 3.5), complex(2.5, 3.5)) } } func BenchmarkRect(b *testing.B) { @@ -828,26 +828,26 @@ func BenchmarkRect(b *testing.B) { } func BenchmarkSin(b *testing.B) { for i := 0; i < b.N; i++ { - Sin(cmplx(2.5, 3.5)) + Sin(complex(2.5, 3.5)) } } func BenchmarkSinh(b *testing.B) { for i := 0; i < b.N; i++ { - Sinh(cmplx(2.5, 3.5)) + Sinh(complex(2.5, 3.5)) } } func BenchmarkSqrt(b *testing.B) { for i := 0; i < b.N; i++ { - Sqrt(cmplx(2.5, 3.5)) + Sqrt(complex(2.5, 3.5)) } } func BenchmarkTan(b *testing.B) { for i := 0; i < b.N; i++ { - Tan(cmplx(2.5, 3.5)) + Tan(complex(2.5, 3.5)) } } func BenchmarkTanh(b *testing.B) { for i := 0; i < b.N; i++ { - Tanh(cmplx(2.5, 3.5)) + Tanh(complex(2.5, 3.5)) } } diff --git a/src/pkg/cmath/conj.go b/src/pkg/cmath/conj.go index 7a19e8631..776b57da7 100644 --- a/src/pkg/cmath/conj.go +++ b/src/pkg/cmath/conj.go @@ -5,4 +5,4 @@ package cmath // Conj returns the complex conjugate of x. -func Conj(x complex128) complex128 { return cmplx(real(x), -imag(x)) } +func Conj(x complex128) complex128 { return complex(real(x), -imag(x)) } diff --git a/src/pkg/cmath/exp.go b/src/pkg/cmath/exp.go index 1a639c596..64c1ef409 100644 --- a/src/pkg/cmath/exp.go +++ b/src/pkg/cmath/exp.go @@ -51,5 +51,5 @@ import "math" func Exp(x complex128) complex128 { r := math.Exp(real(x)) s, c := math.Sincos(imag(x)) - return cmplx(r*c, r*s) + return complex(r*c, r*s) } diff --git a/src/pkg/cmath/isinf.go b/src/pkg/cmath/isinf.go index f17a752ec..f23d2dea7 100644 --- a/src/pkg/cmath/isinf.go +++ b/src/pkg/cmath/isinf.go @@ -14,8 +14,8 @@ func IsInf(x complex128) bool { return false } -// Inf returns a complex infinity, cmplx(+Inf, +Inf). +// Inf returns a complex infinity, complex(+Inf, +Inf). func Inf() complex128 { inf := math.Inf(1) - return cmplx(inf, inf) + return complex(inf, inf) } diff --git a/src/pkg/cmath/isnan.go b/src/pkg/cmath/isnan.go index 8e971dbd3..2063bb835 100644 --- a/src/pkg/cmath/isnan.go +++ b/src/pkg/cmath/isnan.go @@ -21,5 +21,5 @@ func IsNaN(x complex128) bool { // NaN returns a complex ``not-a-number'' value. func NaN() complex128 { nan := math.NaN() - return cmplx(nan, nan) + return complex(nan, nan) } diff --git a/src/pkg/cmath/log.go b/src/pkg/cmath/log.go index b42062b2a..8e6964fee 100644 --- a/src/pkg/cmath/log.go +++ b/src/pkg/cmath/log.go @@ -55,7 +55,7 @@ import "math" // Log returns the natural logarithm of x. func Log(x complex128) complex128 { - return cmplx(math.Log(Abs(x)), Phase(x)) + return complex(math.Log(Abs(x)), Phase(x)) } // Log10 returns the decimal logarithm of x. diff --git a/src/pkg/cmath/pow.go b/src/pkg/cmath/pow.go index de2c4db56..68e1207c6 100644 --- a/src/pkg/cmath/pow.go +++ b/src/pkg/cmath/pow.go @@ -46,7 +46,7 @@ import "math" func Pow(x, y complex128) complex128 { modulus := Abs(x) if modulus == 0 { - return cmplx(0, 0) + return complex(0, 0) } r := math.Pow(modulus, real(y)) arg := Phase(x) @@ -56,5 +56,5 @@ func Pow(x, y complex128) complex128 { theta += imag(y) * math.Log(modulus) } s, c := math.Sincos(theta) - return cmplx(r*c, r*s) + return complex(r*c, r*s) } diff --git a/src/pkg/cmath/rect.go b/src/pkg/cmath/rect.go index 1a88d8679..b955f0bf7 100644 --- a/src/pkg/cmath/rect.go +++ b/src/pkg/cmath/rect.go @@ -9,5 +9,5 @@ import "math" // Rect returns the complex number x with polar coordinates r, θ. func Rect(r, θ float64) complex128 { s, c := math.Sincos(θ) - return cmplx(r*c, r*s) + return complex(r*c, r*s) } diff --git a/src/pkg/cmath/sin.go b/src/pkg/cmath/sin.go index 1b79da493..8900ecdde 100644 --- a/src/pkg/cmath/sin.go +++ b/src/pkg/cmath/sin.go @@ -53,7 +53,7 @@ import "math" func Sin(x complex128) complex128 { s, c := math.Sincos(real(x)) sh, ch := sinhcosh(imag(x)) - return cmplx(s*ch, c*sh) + return complex(s*ch, c*sh) } // Complex hyperbolic sine @@ -73,7 +73,7 @@ func Sin(x complex128) complex128 { func Sinh(x complex128) complex128 { s, c := math.Sincos(imag(x)) sh, ch := sinhcosh(real(x)) - return cmplx(c*sh, s*ch) + return complex(c*sh, s*ch) } // Complex circular cosine @@ -98,7 +98,7 @@ func Sinh(x complex128) complex128 { func Cos(x complex128) complex128 { s, c := math.Sincos(real(x)) sh, ch := sinhcosh(imag(x)) - return cmplx(c*ch, -s*sh) + return complex(c*ch, -s*sh) } // Complex hyperbolic cosine @@ -117,7 +117,7 @@ func Cos(x complex128) complex128 { func Cosh(x complex128) complex128 { s, c := math.Sincos(imag(x)) sh, ch := sinhcosh(real(x)) - return cmplx(c*ch, s*sh) + return complex(c*ch, s*sh) } // calculate sinh and cosh diff --git a/src/pkg/cmath/sqrt.go b/src/pkg/cmath/sqrt.go index 58bc4b691..e77a9b9df 100644 --- a/src/pkg/cmath/sqrt.go +++ b/src/pkg/cmath/sqrt.go @@ -57,20 +57,20 @@ import "math" func Sqrt(x complex128) complex128 { if imag(x) == 0 { if real(x) == 0 { - return cmplx(0, 0) + return complex(0, 0) } if real(x) < 0 { - return cmplx(0, math.Sqrt(-real(x))) + return complex(0, math.Sqrt(-real(x))) } - return cmplx(math.Sqrt(real(x)), 0) + return complex(math.Sqrt(real(x)), 0) } if real(x) == 0 { if imag(x) < 0 { r := math.Sqrt(-0.5 * imag(x)) - return cmplx(r, -r) + return complex(r, -r) } r := math.Sqrt(0.5 * imag(x)) - return cmplx(r, r) + return complex(r, r) } a := real(x) b := imag(x) @@ -97,7 +97,7 @@ func Sqrt(x complex128) complex128 { r *= scale } if b < 0 { - return cmplx(t, -r) + return complex(t, -r) } - return cmplx(t, r) + return complex(t, r) } diff --git a/src/pkg/cmath/tan.go b/src/pkg/cmath/tan.go index d1945cd79..94b517521 100644 --- a/src/pkg/cmath/tan.go +++ b/src/pkg/cmath/tan.go @@ -64,7 +64,7 @@ func Tan(x complex128) complex128 { if d == 0 { return Inf() } - return cmplx(math.Sin(2*real(x))/d, math.Sinh(2*imag(x))/d) + return complex(math.Sin(2*real(x))/d, math.Sinh(2*imag(x))/d) } // Complex hyperbolic tangent @@ -85,7 +85,7 @@ func Tanh(x complex128) complex128 { if d == 0 { return Inf() } - return cmplx(math.Sinh(2*real(x))/d, math.Sin(2*imag(x))/d) + return complex(math.Sinh(2*real(x))/d, math.Sin(2*imag(x))/d) } // Program to subtract nearest integer multiple of PI @@ -114,11 +114,11 @@ func tanSeries(z complex128) float64 { x = reducePi(x) x = x * x y = y * y - x2 := float64(1) - y2 := float64(1) - f := float64(1) - rn := float64(0) - d := float64(0) + x2 := 1.0 + y2 := 1.0 + f := 1.0 + rn := 0.0 + d := 0.0 for { rn += 1 f *= rn @@ -180,5 +180,5 @@ func Cot(x complex128) complex128 { if d == 0 { return Inf() } - return cmplx(math.Sin(2*real(x))/d, -math.Sinh(2*imag(x))/d) + return complex(math.Sin(2*real(x))/d, -math.Sinh(2*imag(x))/d) } |