- replaced gofmt expression formatting algorithm with
rsc's algorithm
- applied gofmt -w misc src
- partial CL (last chunk)
R=rsc, r
http://go/go-review/1024041
diff --git a/src/pkg/math/all_test.go b/src/pkg/math/all_test.go
index 7e53044..8b4299e 100644
--- a/src/pkg/math/all_test.go
+++ b/src/pkg/math/all_test.go
@@ -155,13 +155,13 @@
}
func tolerance(a, b, e float64) bool {
- d := a-b;
+ d := a - b;
if d < 0 {
d = -d
}
if a != 0 {
- e = e*a;
+ e = e * a;
if e < 0 {
e = -e
}
@@ -173,7 +173,7 @@
func TestAsin(t *testing.T) {
for i := 0; i < len(vf); i++ {
- if f := Asin(vf[i]/10); !veryclose(asin[i], f) {
+ if f := Asin(vf[i] / 10); !veryclose(asin[i], f) {
t.Errorf("Asin(%g) = %g, want %g\n", vf[i]/10, f, asin[i])
}
}
@@ -266,7 +266,7 @@
func TestHypot(t *testing.T) {
for i := 0; i < len(vf); i++ {
- a := Fabs(tanh[i]*Sqrt(2));
+ a := Fabs(tanh[i] * Sqrt(2));
if f := Hypot(tanh[i], tanh[i]); !veryclose(a, f) {
t.Errorf("Hypot(%g, %g) = %g, want %g\n", tanh[i], tanh[i], f, a)
}
diff --git a/src/pkg/math/asin.go b/src/pkg/math/asin.go
index c4696e8..3ba36ab 100644
--- a/src/pkg/math/asin.go
+++ b/src/pkg/math/asin.go
@@ -27,7 +27,7 @@
if x > 0.7 {
temp = Pi/2 - Atan(temp/x)
} else {
- temp = Atan(x/temp)
+ temp = Atan(x / temp)
}
if sign {
diff --git a/src/pkg/math/atan.go b/src/pkg/math/atan.go
index 641f905..1582031 100644
--- a/src/pkg/math/atan.go
+++ b/src/pkg/math/atan.go
@@ -31,10 +31,10 @@
Q1 = .207933497444540981287275926e4;
Q0 = .89678597403663861962481162e3;
)
- sq := arg*arg;
- value := ((((P4*sq + P3)*sq + P2)*sq + P1)*sq + P0);
- value = value/(((((sq+Q4)*sq + Q3)*sq + Q2)*sq + Q1)*sq + Q0);
- return value*arg;
+ sq := arg * arg;
+ value := ((((P4*sq+P3)*sq+P2)*sq + P1) * sq + P0);
+ value = value / (((((sq+Q4)*sq+Q3)*sq+Q2)*sq+Q1)*sq + Q0);
+ return value * arg;
}
/*
diff --git a/src/pkg/math/atan2.go b/src/pkg/math/atan2.go
index 95226b9..7165c53 100644
--- a/src/pkg/math/atan2.go
+++ b/src/pkg/math/atan2.go
@@ -12,16 +12,16 @@
// Determine the quadrant and call atan.
if x+y == x {
if x >= 0 {
- return Pi/2
+ return Pi / 2
}
return -Pi / 2;
}
- q := Atan(x/y);
+ q := Atan(x / y);
if y < 0 {
if q <= 0 {
- return q+Pi
+ return q + Pi
}
- return q-Pi;
+ return q - Pi;
}
return q;
}
diff --git a/src/pkg/math/bits.go b/src/pkg/math/bits.go
index b1bf2da..5372c68 100644
--- a/src/pkg/math/bits.go
+++ b/src/pkg/math/bits.go
@@ -9,7 +9,7 @@
uvinf = 0x7FF0000000000000;
uvneginf = 0xFFF0000000000000;
mask = 0x7FF;
- shift = 64-11-1;
+ shift = 64 - 11 - 1;
bias = 1022;
)
@@ -51,9 +51,9 @@
return
}
x := Float64bits(f);
- exp = int((x>>shift)&mask)-bias;
- x &^= mask<<shift;
- x |= bias<<shift;
+ exp = int((x>>shift)&mask) - bias;
+ x &^= mask << shift;
+ x |= bias << shift;
frac = Float64frombits(x);
return;
}
@@ -62,7 +62,7 @@
// It returns frac × 2<sup>exp</sup>.
func Ldexp(frac float64, exp int) float64 {
x := Float64bits(frac);
- exp += int(x>>shift)&mask;
+ exp += int(x>>shift) & mask;
if exp <= 0 {
return 0 // underflow
}
@@ -72,8 +72,8 @@
}
return Inf(1);
}
- x &^= mask<<shift;
- x |= uint64(exp)<<shift;
+ x &^= mask << shift;
+ x |= uint64(exp) << shift;
return Float64frombits(x);
}
@@ -97,6 +97,6 @@
x &^= 1<<(64-11-e) - 1
}
int = Float64frombits(x);
- frac = f-int;
+ frac = f - int;
return;
}
diff --git a/src/pkg/math/const.go b/src/pkg/math/const.go
index 19fa8fa..68ecefa 100644
--- a/src/pkg/math/const.go
+++ b/src/pkg/math/const.go
@@ -18,9 +18,9 @@
SqrtPhi = 1.27201964951406896425242246173749149171560804184009624861664038; // A139339
Ln2 = 0.693147180559945309417232121458176568075500134360255254120680009; // A002162
- Log2E = 1/Ln2;
+ Log2E = 1 / Ln2;
Ln10 = 2.30258509299404568401799145468436420760110148862877297603332790; // A002392
- Log10E = 1/Ln10;
+ Log10E = 1 / Ln10;
)
// Floating-point limit values.
diff --git a/src/pkg/math/exp.go b/src/pkg/math/exp.go
index a5f5620..cdee0d7 100644
--- a/src/pkg/math/exp.go
+++ b/src/pkg/math/exp.go
@@ -101,7 +101,7 @@
Overflow = 7.09782712893383973096e+02;
Underflow = -7.45133219101941108420e+02;
- NearZero = 1.0/(1<<28); // 2^-28
+ NearZero = 1.0 / (1 << 28); // 2^-28
)
// special cases
@@ -127,13 +127,13 @@
k = int(Log2e*x + 0.5)
}
hi := x - float64(k)*Ln2Hi;
- lo := float64(k)*Ln2Lo;
- r := hi-lo;
+ lo := float64(k) * Ln2Lo;
+ r := hi - lo;
// compute
- t := r*r;
- c := r - t*(P1 + t*(P2 + t*(P3 + t*(P4 + t*P5))));
- y := 1-((lo - (r*c)/(2-c))-hi);
+ t := r * r;
+ c := r - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
+ y := 1 - ((lo - (r*c)/(2-c)) - hi);
// TODO(rsc): make sure Ldexp can handle boundary k
return Ldexp(y, k);
}
diff --git a/src/pkg/math/floor.go b/src/pkg/math/floor.go
index 7a99985..96532ac 100644
--- a/src/pkg/math/floor.go
+++ b/src/pkg/math/floor.go
@@ -10,7 +10,7 @@
if x < 0 {
d, fract := Modf(-x);
if fract != 0.0 {
- d = d+1
+ d = d + 1
}
return -d;
}
diff --git a/src/pkg/math/fmod.go b/src/pkg/math/fmod.go
index 34fbfbd..9539b2a 100644
--- a/src/pkg/math/fmod.go
+++ b/src/pkg/math/fmod.go
@@ -29,7 +29,7 @@
for r >= y {
rfr, rexp := Frexp(r);
if rfr < yfr {
- rexp = rexp-1
+ rexp = rexp - 1
}
r = r - Ldexp(y, rexp-yexp);
}
diff --git a/src/pkg/math/hypot.go b/src/pkg/math/hypot.go
index 7ff8f4b..9585da4 100644
--- a/src/pkg/math/hypot.go
+++ b/src/pkg/math/hypot.go
@@ -31,19 +31,19 @@
}
pfac := p;
- q = q/p;
+ q = q / p;
r := q;
p = 1;
for {
- r = r*r;
- s := r+4;
+ r = r * r;
+ s := r + 4;
if s == 4 {
- return p*pfac
+ return p * pfac
}
- r = r/s;
+ r = r / s;
p = p + 2*r*p;
- q = q*r;
- r = q/p;
+ q = q * r;
+ r = q / p;
}
panic("unreachable");
}
diff --git a/src/pkg/math/log.go b/src/pkg/math/log.go
index bf8b49a..e926501 100644
--- a/src/pkg/math/log.go
+++ b/src/pkg/math/log.go
@@ -103,18 +103,18 @@
f1 *= 2;
ki--;
}
- f := f1-1;
+ f := f1 - 1;
k := float64(ki);
// compute
- s := f/(2+f);
- s2 := s*s;
- s4 := s2*s2;
- t1 := s2*(L1 + s4*(L3 + s4*(L5 + s4*L7)));
- t2 := s4*(L2 + s4*(L4 + s4*L6));
- R := t1+t2;
- hfsq := 0.5*f*f;
- return k*Ln2Hi - ((hfsq-(s*(hfsq+R) + k*Ln2Lo))-f);
+ s := f / (2 + f);
+ s2 := s * s;
+ s4 := s2 * s2;
+ t1 := s2 * (L1 + s4*(L3+s4*(L5+s4*L7)));
+ t2 := s4 * (L2 + s4*(L4+s4*L6));
+ R := t1 + t2;
+ hfsq := 0.5 * f * f;
+ return k*Ln2Hi - ((hfsq - (s*(hfsq+R) + k*Ln2Lo)) - f);
}
// Log10 returns the decimal logarithm of x.
@@ -123,5 +123,5 @@
if x <= 0 {
return NaN()
}
- return Log(x)*(1/Ln10);
+ return Log(x) * (1 / Ln10);
}
diff --git a/src/pkg/math/pow.go b/src/pkg/math/pow.go
index 9754809..c91dc44 100644
--- a/src/pkg/math/pow.go
+++ b/src/pkg/math/pow.go
@@ -20,7 +20,7 @@
case y == 0.5:
return Sqrt(x)
case y == -0.5:
- return 1/Sqrt(x)
+ return 1 / Sqrt(x)
}
absy := y;
@@ -34,7 +34,7 @@
return NaN()
}
if yi >= 1<<63 {
- return Exp(y*Log(x))
+ return Exp(y * Log(x))
}
// ans = a1 * 2^ae (= 1 for now).
@@ -47,7 +47,7 @@
yf--;
yi++;
}
- a1 = Exp(yf*Log(x));
+ a1 = Exp(yf * Log(x));
}
// ans *= x^yi
@@ -72,7 +72,7 @@
// if flip { ans = 1 / ans }
// but in the opposite order
if flip {
- a1 = 1/a1;
+ a1 = 1 / a1;
ae = -ae;
}
return Ldexp(a1, ae);
diff --git a/src/pkg/math/pow10.go b/src/pkg/math/pow10.go
index 1ae6dcd..edba40a 100644
--- a/src/pkg/math/pow10.go
+++ b/src/pkg/math/pow10.go
@@ -18,20 +18,20 @@
// Pow10 returns 10**x, the base-10 exponential of x.
func Pow10(e int) float64 {
if e < 0 {
- return 1/Pow10(-e)
+ return 1 / Pow10(-e)
}
if e < len(pow10tab) {
return pow10tab[e]
}
- m := e/2;
- return Pow10(m)*Pow10(e-m);
+ m := e / 2;
+ return Pow10(m) * Pow10(e-m);
}
func init() {
pow10tab[0] = 1.0e0;
pow10tab[1] = 1.0e1;
for i := 2; i < len(pow10tab); i++ {
- m := i/2;
- pow10tab[i] = pow10tab[m]*pow10tab[i-m];
+ m := i / 2;
+ pow10tab[i] = pow10tab[m] * pow10tab[i-m];
}
}
diff --git a/src/pkg/math/sin.go b/src/pkg/math/sin.go
index 2c6f007..adff067 100644
--- a/src/pkg/math/sin.go
+++ b/src/pkg/math/sin.go
@@ -20,33 +20,33 @@
)
if x < 0 {
x = -x;
- quad = quad+2;
+ quad = quad + 2;
}
- x = x*(2/Pi); /* underflow? */
+ x = x * (2 / Pi); /* underflow? */
var y float64;
if x > 32764 {
var e float64;
e, y = Modf(x);
- e = e+float64(quad);
- _, f := Modf(0.25*e);
+ e = e + float64(quad);
+ _, f := Modf(0.25 * e);
quad = int(e - 4*f);
} else {
k := int32(x);
- y = x-float64(k);
- quad = (quad+int(k))&3;
+ y = x - float64(k);
+ quad = (quad + int(k)) & 3;
}
if quad&1 != 0 {
- y = 1-y
+ y = 1 - y
}
if quad > 1 {
y = -y
}
- yy := y*y;
- temp1 := ((((P4*yy + P3)*yy + P2)*yy + P1)*yy + P0)*y;
- temp2 := ((((yy+Q3)*yy + Q2)*yy + Q1)*yy + Q0);
- return temp1/temp2;
+ yy := y * y;
+ temp1 := ((((P4*yy+P3)*yy+P2)*yy+P1)*yy + P0) * y;
+ temp2 := ((((yy+Q3)*yy+Q2)*yy + Q1) * yy + Q0);
+ return temp1 / temp2;
}
// Cos returns the cosine of x.
diff --git a/src/pkg/math/sinh.go b/src/pkg/math/sinh.go
index 72775da..968b89b 100644
--- a/src/pkg/math/sinh.go
+++ b/src/pkg/math/sinh.go
@@ -39,15 +39,15 @@
var temp float64;
switch true {
case x > 21:
- temp = Exp(x)/2
+ temp = Exp(x) / 2
case x > 0.5:
- temp = (Exp(x)-Exp(-x))/2
+ temp = (Exp(x) - Exp(-x)) / 2
default:
- sq := x*x;
- temp = (((P3*sq + P2)*sq + P1)*sq + P0)*x;
- temp = temp/(((sq+Q2)*sq + Q1)*sq + Q0);
+ sq := x * x;
+ temp = (((P3*sq+P2)*sq+P1)*sq + P0) * x;
+ temp = temp / (((sq+Q2)*sq+Q1)*sq + Q0);
}
if sign {
@@ -62,7 +62,7 @@
x = -x
}
if x > 21 {
- return Exp(x)/2
+ return Exp(x) / 2
}
- return (Exp(x)+Exp(-x))/2;
+ return (Exp(x) + Exp(-x)) / 2;
}
diff --git a/src/pkg/math/sqrt.go b/src/pkg/math/sqrt.go
index 7a5b69a..63f458b 100644
--- a/src/pkg/math/sqrt.go
+++ b/src/pkg/math/sqrt.go
@@ -32,34 +32,34 @@
y, exp := Frexp(x);
for y < 0.5 {
- y = y*2;
- exp = exp-1;
+ y = y * 2;
+ exp = exp - 1;
}
if exp&1 != 0 {
- y = y*2;
- exp = exp-1;
+ y = y * 2;
+ exp = exp - 1;
}
- temp := 0.5*(1+y);
+ temp := 0.5 * (1 + y);
for exp > 60 {
- temp = temp*float64(1<<30);
- exp = exp-60;
+ temp = temp * float64(1<<30);
+ exp = exp - 60;
}
for exp < -60 {
- temp = temp/float64(1<<30);
- exp = exp+60;
+ temp = temp / float64(1<<30);
+ exp = exp + 60;
}
if exp >= 0 {
- exp = 1<<uint(exp/2);
- temp = temp*float64(exp);
+ exp = 1 << uint(exp/2);
+ temp = temp * float64(exp);
} else {
- exp = 1<<uint(-exp / 2);
- temp = temp/float64(exp);
+ exp = 1 << uint(-exp/2);
+ temp = temp / float64(exp);
}
for i := 0; i <= 4; i++ {
- temp = 0.5*(temp + x/temp)
+ temp = 0.5 * (temp + x/temp)
}
return temp;
}
diff --git a/src/pkg/math/tan.go b/src/pkg/math/tan.go
index cc57155..09ade2d 100644
--- a/src/pkg/math/tan.go
+++ b/src/pkg/math/tan.go
@@ -29,14 +29,14 @@
x = -x;
sign = true;
}
- x = x*(4/Pi); /* overflow? */
+ x = x * (4 / Pi); /* overflow? */
var e float64;
e, x = Modf(x);
i := int32(e);
- switch i&3 {
+ switch i & 3 {
case 1:
- x = 1-x;
+ x = 1 - x;
flag = true;
case 2:
@@ -44,19 +44,19 @@
flag = true;
case 3:
- x = 1-x;
+ x = 1 - x;
sign = !sign;
}
- xsq := x*x;
- temp := ((((P4*xsq + P3)*xsq + P2)*xsq + P1)*xsq + P0)*x;
- temp = temp/(((xsq+Q2)*xsq + Q1)*xsq + Q0);
+ xsq := x * x;
+ temp := ((((P4*xsq+P3)*xsq+P2)*xsq+P1)*xsq + P0) * x;
+ temp = temp / (((xsq+Q2)*xsq+Q1)*xsq + Q0);
if flag {
if temp == 0 {
panic(NaN())
}
- temp = 1/temp;
+ temp = 1 / temp;
}
if sign {
temp = -temp
diff --git a/src/pkg/math/tanh.go b/src/pkg/math/tanh.go
index e6d4da8..93c68a6 100644
--- a/src/pkg/math/tanh.go
+++ b/src/pkg/math/tanh.go
@@ -25,5 +25,5 @@
if x > 21 {
return 1
}
- return Sinh(x)/Cosh(x);
+ return Sinh(x) / Cosh(x);
}