Skip to content

Commit

Permalink
delete float, complex - code changes
Browse files Browse the repository at this point in the history
also:
	cmplx -> complex
	float64(1.0) -> 1.0
	float64(1) -> 1.0

R=gri, r, gri1, r2
CC=golang-dev
https://golang.org/cl/3991043
  • Loading branch information
rsc committed Jan 20, 2011
1 parent 0849944 commit f2b5a07
Show file tree
Hide file tree
Showing 122 changed files with 3,317 additions and 3,531 deletions.
32 changes: 16 additions & 16 deletions src/pkg/cmath/asin.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,30 @@ 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.
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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
62 changes: 31 additions & 31 deletions src/pkg/cmath/cmath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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) {
Expand All @@ -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))
}
}
2 changes: 1 addition & 1 deletion src/pkg/cmath/conj.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
2 changes: 1 addition & 1 deletion src/pkg/cmath/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions src/pkg/cmath/isinf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion src/pkg/cmath/isnan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion src/pkg/cmath/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/cmath/pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion src/pkg/cmath/rect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions src/pkg/cmath/sin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/pkg/cmath/sqrt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Loading

0 comments on commit f2b5a07

Please sign in to comment.