]> Cypherpunks repositories - gostls13.git/commitdiff
converted double to float64
authorKen Thompson <ken@golang.org>
Wed, 9 Jul 2008 03:48:41 +0000 (20:48 -0700)
committerKen Thompson <ken@golang.org>
Wed, 9 Jul 2008 03:48:41 +0000 (20:48 -0700)
SVN=126446

18 files changed:
src/lib/math/asin.go
src/lib/math/atan.go
src/lib/math/atan2.go
src/lib/math/exp.go
src/lib/math/fabs.go
src/lib/math/floor.go
src/lib/math/fmod.go
src/lib/math/hypot.go
src/lib/math/log.go
src/lib/math/main.go
src/lib/math/pow.go
src/lib/math/pow10.go
src/lib/math/sin.go
src/lib/math/sinh.go
src/lib/math/sqrt.go
src/lib/math/sys.go
src/lib/math/tan.go
src/lib/math/tanh.go

index a0135f48fdb357d26f0bc134707316f02a83b97d..f7a286b32de123ae0a351fcab513406464f2d1f4 100644 (file)
@@ -18,13 +18,13 @@ export      asin, acos
 
 const
 (
-       pio2    = .15707963267948966192313216e1;
+       pio2 = .15707963267948966192313216e1
 )
 
 func
-asin(arg double)double
+asin(arg float64)float64
 {
-       var temp, x double;
+       var temp, x float64;
        var sign bool;
 
        sign = false;
@@ -51,7 +51,7 @@ asin(arg double)double
 }
 
 func
-acos(arg double)double
+acos(arg float64)float64
 {
        if(arg > 1 || arg < -1) {
                return sys.NaN();
index 064b8d4fca544112bb09a655da3b03393565eed1..0c284b8d90bd40fcf98cbc181b7423203eb29d8e 100644 (file)
@@ -7,12 +7,12 @@ package math
 export atan
 
 /*
      floating-point arctangent
-
      atan returns the value of the arctangent of its
      argument in the range [-pi/2,pi/2].
      there are no error returns.
      coefficients are #5077 from Hart & Cheney. (19.56D)
*     floating-point arctangent
+ *
*     atan returns the value of the arctangent of its
*     argument in the range [-pi/2,pi/2].
*     there are no error returns.
*     coefficients are #5077 from Hart & Cheney. (19.56D)
 */
 
 
@@ -35,14 +35,14 @@ const
 )
 
 /*
      xatan evaluates a series valid in the
      range [-0.414...,+0.414...]. (tan(pi/8))
*     xatan evaluates a series valid in the
*     range [-0.414...,+0.414...]. (tan(pi/8))
  */
 
 func
-xatan(arg double) double
+xatan(arg float64) float64
 {
-       var argsq, value double;
+       var argsq, value float64;
 
        argsq = arg*arg;
        value = ((((p4*argsq + p3)*argsq + p2)*argsq + p1)*argsq + p0);
@@ -51,12 +51,11 @@ xatan(arg double) double
 }
 
 /*
      satan reduces its argument (known to be positive)
      to the range [0,0.414...] and calls xatan.
*     satan reduces its argument (known to be positive)
*     to the range [0,0.414...] and calls xatan.
  */
-
 func
-satan(arg double) double
+satan(arg float64) float64
 {
 
        if arg < sq2m1 {
@@ -69,12 +68,11 @@ satan(arg double) double
 }
 
 /*
      atan makes its argument positive and
      calls the inner routine satan.
*     atan makes its argument positive and
*     calls the inner routine satan.
  */
-
 func
-atan(arg double) double
+atan(arg float64) float64
 {
 
        if arg > 0 {
index b3bddf752193bf73f1591a5ac41df303e79eb400..c002c8354f1d1c66e263759935be7eb74204af76 100644 (file)
@@ -8,9 +8,9 @@ import  math "atan"
 export atan2
 
 /*
      atan2 discovers what quadrant the angle
      is in and calls atan.
-*/
*     atan2 discovers what quadrant the angle
*     is in and calls atan.
+ */
 
 const
 (
@@ -19,9 +19,9 @@ const
 )
 
 func
-atan2(arg1, arg2 double) double
+atan2(arg1, arg2 float64) float64
 {
-       var x double;
+       var x float64;
 
        if arg1+arg2 == arg1 {
                if arg1 >= 0 {
index dc851a084f35a95d014a750fd0ea3d443819feed..cce9386b776e2fb7afc33d3f0dd0e0fa6d1a3b92 100644 (file)
@@ -8,11 +8,11 @@ import        math "floor"
 export exp
 
 /*
      exp returns the exponential func of its
      floating-point argument.
-
      The coefficients are #1069 from Hart and Cheney. (22.35D)
-*/
*     exp returns the exponential func of its
*     floating-point argument.
+ *
*     The coefficients are #1069 from Hart and Cheney. (22.35D)
+ */
 
 const
 (
@@ -28,16 +28,16 @@ const
 )
 
 func
-exp(arg double) double
+exp(arg float64) float64
 {
-       var x, fract, temp1, temp2, xsq double;
+       var x, fract, temp1, temp2, xsq float64;
        var ent int;
 
        if arg == 0. {
                return 1;
        }
        if arg < -maxf {
-               return 0.;
+               return 0;
        }
        if arg > maxf {
                return sys.Inf(1)
@@ -45,7 +45,7 @@ exp(arg double) double
 
        x = arg*log2e;
        ent = int(floor(x));
-       fract = (x-double(ent)) - 0.5;
+       fract = (x-float64(ent)) - 0.5;
        xsq = fract*fract;
        temp1 = ((p2*xsq+p1)*xsq+p0)*fract;
        temp2 = ((xsq+q2)*xsq+q1)*xsq + q0;
index 4a184be33ae8907a7a4c651588d07d742fd54ba3..23ea55b9935c81b8c87d8a1c658b8e7d1105f36b 100644 (file)
@@ -7,7 +7,7 @@ package math
 export fabs
 
 func
-fabs(arg double) double
+fabs(arg float64) float64
 {
 
        if arg < 0 {
index 108b40395c73b1a6cc07c7a52e26176fc9e636e0..750310e0bae5d489bddfc48c01bf2f77b615f28f 100644 (file)
@@ -12,9 +12,9 @@ export        floor, ceil
  */
 
 func
-floor(arg double) double
+floor(arg float64) float64
 {
-       var fract, d double;
+       var fract, d float64;
 
        d = arg;
        if d < 0 {
@@ -30,7 +30,7 @@ floor(arg double) double
 }
 
 func
-ceil(arg double) double
+ceil(arg float64) float64
 {
        return -floor(-arg);
 }
index 65222ac03b8e7d5c4c31aa668c2a4dc00daadb51..b7dd90ee8282888e0781441187d64e4f52a59833 100644 (file)
@@ -7,14 +7,14 @@ package math
 export fmod
 
 /*
      floating-point mod func without infinity or NaN checking
*     floating-point mod func without infinity or NaN checking
  */
 
 func
-fmod(x, y double) double
+fmod(x, y float64) float64
 {
        var yexp, rexp int;
-       var r, yfr, rfr double;
+       var r, yfr, rfr float64;
        var sign bool;
 
        if y == 0 {
index 51e6662ddcda4b82d4c5303cb017fad68403b947..2c7e9c5815b3ee164aa3e52348da80b2b31be197 100644 (file)
@@ -7,17 +7,17 @@ package math
 export hypot
 
 /*
      hypot -- sqrt(p*p + q*q), but overflows only if the result does.
      See Cleve Moler and Donald Morrison,
      Replacing Square Roots by Pythagorean Sums
      IBM Journal of Research and Development,
      Vol. 27, Number 6, pp. 577-581, Nov. 1983
*     hypot -- sqrt(p*p + q*q), but overflows only if the result does.
*     See Cleve Moler and Donald Morrison,
*     Replacing Square Roots by Pythagorean Sums
*     IBM Journal of Research and Development,
*     Vol. 27, Number 6, pp. 577-581, Nov. 1983
  */
 
 func
-hypot(p, q double) double
+hypot(p, q float64) float64
 {
-       var r, s, pfac double;
+       var r, s, pfac float64;
 
        if p < 0 {
                p = -p;
@@ -40,7 +40,7 @@ hypot(p, q double) double
        q = q/p;
        r = q;
        p = 1;
-       for ;; {
+       for {
                r = r*r;
                s = r+4;
                if s == 4 {
index 96b3d96956cba34478f2b361b63b69b74d6d3473..927a7acdf08240bb87837be901818222f83538e0 100644 (file)
@@ -7,13 +7,13 @@ package math
 export log, log10
 
 /*
      log returns the natural logarithm of its floating
      point argument.
-
      The coefficients are #2705 from Hart & Cheney. (19.38D)
-
      It calls frexp.
-*/
*     log returns the natural logarithm of its floating
*     point argument.
+ *
*     The coefficients are #2705 from Hart & Cheney. (19.38D)
+ *
*     It calls frexp.
+ */
 
 const
 (
@@ -30,9 +30,9 @@ const
 )
 
 func
-log(arg double) double
+log(arg float64) float64
 {
-       var x, z, zsq, temp double;
+       var x, z, zsq, temp float64;
        var exp int;
 
        if arg <= 0 {
@@ -54,12 +54,12 @@ log(arg double) double
 
        temp = ((p3*zsq + p2)*zsq + p1)*zsq + p0;
        temp = temp/(((zsq + q2)*zsq + q1)*zsq + q0);
-       temp = temp*z + double(exp)*log2;
+       temp = temp*z + float64(exp)*log2;
        return temp;
 }
 
 func
-log10(arg double) double
+log10(arg float64) float64
 {
 
        if arg <= 0 {
index 0006151d9ffacb1f08c0e529acdacae39737a748..7b266d878aafd15c480ecef979fb8e442111594f 100644 (file)
@@ -6,7 +6,7 @@
 package main
 
 //import math "math"
-//////////////////
+
  import math "asin"
  import math "atan"
  import math "atan2"
@@ -25,29 +25,26 @@ package main
  import math "tanh"
 
 
-const
-(
-       length  = 10;
-)
+const  length  = 10;
 
 var
 (
-       vf      [length]double;
-       asin    [length]double;
-       atan    [length]double;
-       exp     [length]double;
-       floor   [length]double;
-       log     [length]double;
-       pow     [length]double;
-       sin     [length]double;
-       sinh    [length]double;
-       sqrt    [length]double;
-       tan     [length]double;
-       tanh    [length]double;
+       vf      [length]float64;
+       asin    [length]float64;
+       atan    [length]float64;
+       exp     [length]float64;
+       floor   [length]float64;
+       log     [length]float64;
+       pow     [length]float64;
+       sin     [length]float64;
+       sinh    [length]float64;
+       sqrt    [length]float64;
+       tan     [length]float64;
+       tanh    [length]float64;
 )
 
 func   init();
-func   ck(a,b double);
+func   ck(a,b float64);
 
 func
 main()
@@ -73,7 +70,7 @@ main()
 }
 
 func
-ck(a,b double)
+ck(a,b float64)
 {
        d := a-b;
        if d < 0 {
index 958bb371c147ab834a43bdc5ab62a4b4d0877510..2581f8d33734a2004d0cedf6a5f87303cf0a113a 100644 (file)
@@ -15,9 +15,9 @@ export                pow
  */
 
 func
-pow(arg1,arg2 double) double
+pow(arg1,arg2 float64) float64
 {
-       var temp double;
+       var temp float64;
        var l long;
 
        if arg2 < 0 {
@@ -60,10 +60,10 @@ pow(arg1,arg2 double) double
                if l&1 != 0 {
                        temp = temp*arg1;
                }
-               l = l>>1;
+               l >>= 1;
                if l == 0 {
                        return temp;
                }
-               arg1 = arg1*arg1;
+               arg1 *= arg1;
        }
 }
index bb06758ff1ae912d9948c728fccb92c1c2ea6930..43c23edaf0231d3428a8df5c6e99fc50b3c331e0 100644 (file)
@@ -14,15 +14,10 @@ export      pow10
  * the presumption is that GO converts fp numbers better
  * than multipication of lower powers of 10.
  */
-const
-(
-       tabsize         = 70;
-)
-
-var    tab[tabsize] double;
-func   init();
-var    initdone bool;
 
+const  tabsize         = 70;
+var    initdone        bool;
+var    tab[tabsize]    float64;
 //{
 //     1.0e0, 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5, 1.0e6, 1.0e7, 1.0e8, 1.0e9,
 //     1.0e10,1.0e11,1.0e12,1.0e13,1.0e14,1.0e15,1.0e16,1.0e17,1.0e18,1.0e19,
@@ -33,8 +28,10 @@ var  initdone bool;
 //     1.0e60,1.0e61,1.0e62,1.0e63,1.0e64,1.0e65,1.0e66,1.0e67,1.0e68,1.0e69,
 //};
 
+func   init();
+
 func
-pow10(e int) double 
+pow10(e int) float64 
 {
        if !initdone {
                init();
@@ -53,8 +50,11 @@ func
 init()
 {
        initdone = true;
-       tab[0] = 1.0;
-       for i:=1; i<tabsize; i=i+1 {
-               tab[i] = tab[i-1]*10;
+
+       tab[0] = 1.0e0;
+       tab[1] = 1.0e1;
+       for i:=2; i<tabsize; i++ {
+               m := i/2;
+               tab[i] = tab[m] * tab[i-m];
        }
 }
index dabe825128ad254b987f097549a69462dd662d55..e1ac553d3edb81e4a6cee5f033b03515b3990a29 100644 (file)
@@ -21,9 +21,9 @@ const
 )
 
 func
-sinus(arg double, quad int) double
+sinus(arg float64, quad int) float64
 {
-       var e, f, ysq, x, y, temp1, temp2 double;
+       var e, f, ysq, x, y, temp1, temp2 float64;
        var k long;
 
        x = arg;
@@ -34,12 +34,12 @@ sinus(arg double, quad int) double
        x = x * piu2;   /* underflow? */
        if x > 32764 {
                e,y = sys.modf(x);
-               e = e + double(quad);
+               e = e + float64(quad);
                temp1,f = sys.modf(0.25*e);
                quad = int(e - 4*f);
        } else {
                k = long(x);
-               y = x - double(k);
+               y = x - float64(k);
                quad = (quad + int(k)) & 3;
        }
 
@@ -57,7 +57,7 @@ sinus(arg double, quad int) double
 }
 
 func
-cos(arg double) double
+cos(arg float64) float64
 {
        if arg < 0 {
                arg = -arg;
@@ -66,7 +66,7 @@ cos(arg double) double
 }
 
 func
-sin(arg double) double
+sin(arg float64) float64
 {
        return sinus(arg, 0);
 }
index a475171d7ab50ad547e4b42a34b9cb89d86289b8..fd3b50a7d337c13f49c52009dd7fcb91f9002b42 100644 (file)
@@ -8,17 +8,17 @@ import        math "exp"
 export sinh, cosh
 
 /*
      sinh(arg) returns the hyperbolic sine of its floating-
      point argument.
-
      The exponential func is called for arguments
      greater in magnitude than 0.5.
-
      A series is used for arguments smaller in magnitude than 0.5.
      The coefficients are #2029 from Hart & Cheney. (20.36D)
-
      cosh(arg) is computed from the exponential func for
      all arguments.
*     sinh(arg) returns the hyperbolic sine of its floating-
*     point argument.
+ *
*     The exponential func is called for arguments
*     greater in magnitude than 0.5.
+ *
*     A series is used for arguments smaller in magnitude than 0.5.
*     The coefficients are #2029 from Hart & Cheney. (20.36D)
+ *
*     cosh(arg) is computed from the exponential func for
*     all arguments.
  */
 
 const
@@ -33,9 +33,9 @@ const
 )
 
 func
-sinh(arg double) double
+sinh(arg float64) float64
 {
-       var temp, argsq double;
+       var temp, argsq float64;
        var sign bool;
 
        sign = false;
@@ -43,6 +43,7 @@ sinh(arg double) double
                arg = -arg;
                sign = true;
        }
+
        switch true {
        case arg > 21:
                temp = exp(arg)/2;
@@ -63,7 +64,7 @@ sinh(arg double) double
 }
 
 func
-cosh(arg double) double
+cosh(arg float64) float64
 {
        if arg < 0 {
                arg = - arg;
index 4f8a8536d1b0b3d7a100b7f97b18898fb218f6e9..6576208f68c890391a6cd12d630804af60f5ef20 100644 (file)
@@ -7,16 +7,16 @@ package math
 export         sqrt
 
 /*
      sqrt returns the square root of its floating
      point argument. Newton's method.
-
      calls frexp
-*/
*     sqrt returns the square root of its floating
*     point argument. Newton's method.
+ *
*     calls frexp
+ */
 
 func
-sqrt(arg double) double
+sqrt(arg float64) float64
 {
-       var x, temp double;
+       var x, temp float64;
        var exp, i int;
 
        if sys.isInf(arg, 1) {
@@ -25,7 +25,7 @@ sqrt(arg double) double
 
        if arg <= 0 {
                if arg < 0 {
-                       panic "return sys.NaN()"
+                       return sys.NaN();
                }
                return 0;
        }
@@ -43,17 +43,17 @@ sqrt(arg double) double
        temp = 0.5 * (1+x);
 
        for exp > 60 {
-               temp = temp * double(1<<30);
+               temp = temp * float64(1<<30);
                exp = exp - 60;
        }
        for exp < -60 {
-               temp = temp / double(1<<30);
+               temp = temp / float64(1<<30);
                exp = exp + 60;
        }
        if exp >= 0 {
-               temp = temp * double(1 << (exp/2));
+               temp = temp * float64(1 << (exp/2));
        } else {
-               temp = temp / double(1 << (-exp/2));
+               temp = temp / float64(1 << (-exp/2));
        }
 
        for i=0; i<=4; i=i+1 {
index 41356cebaa42e50cecdc028cb61e134f84df0fd7..a24c8196e51bbb0f204eda11f3958396e3e77a2c 100644 (file)
@@ -4,13 +4,13 @@
 
 package sys
 
-func   modf(a double) (x double, y double);
-func   frexp(a double) (e int, m double);
-func   ldexp(f double, e int) double;
+func   modf(a float64) (x float64, y float64);
+func   frexp(a float64) (e int, m float64);
+func   ldexp(f float64, e int) float64;
 
-func   Inf(n int) double;
-func   NaN() double;
-func   isInf(arg double, n int) bool;
+func   Inf(n int) float64;
+func   NaN() float64;
+func   isInf(arg float64, n int) bool;
 
 export modf, frexp, ldexp
 export NaN, isInf, Inf
index 11c03009f2c6b0bd14cb4902571e1de9f8df96f9..6ee6597b6f4ce5d660cd2fdc9f9e48f61108436f 100644 (file)
@@ -7,8 +7,8 @@ package math
 export         tan
 
 /*
      floating point tangent
      Coefficients are #4285 from Hart & Cheney. (19.74D)
*     floating point tangent
*     Coefficients are #4285 from Hart & Cheney. (19.74D)
  */
 
 const
@@ -25,9 +25,9 @@ const
 )
 
 func
-tan(arg double) double
+tan(arg float64) float64
 {
-       var temp, e, x, xsq double;
+       var temp, e, x, xsq float64;
        var i long;
        var flag, sign bool;
 
index 3e299c808f8b455d728a1ee7dd82a54424afe81f..f857423035abedb5129b5a45fb78aa7fad3900de 100644 (file)
@@ -8,15 +8,15 @@ import                math "sinh"
 export         tanh
 
 /*
      tanh(arg) computes the hyperbolic tangent of its floating
      point argument.
-
      sinh and cosh are called except for large arguments, which
      would cause overflow improperly.
*     tanh(arg) computes the hyperbolic tangent of its floating
*     point argument.
+ *
*     sinh and cosh are called except for large arguments, which
*     would cause overflow improperly.
  */
 
 func
-tanh(arg double) double
+tanh(arg float64) float64
 {
        if arg < 0 {
                arg = -arg;