Commit 77e20e8c authored by Ken Thompson's avatar Ken Thompson

converted double to float64

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