mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
converted double to float64
SVN=126446
This commit is contained in:
parent
8e4ee0045f
commit
77e20e8cec
18 changed files with 141 additions and 145 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ 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 {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ 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;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ package math
|
|||
export fabs
|
||||
|
||||
func
|
||||
fabs(arg double) double
|
||||
fabs(arg float64) float64
|
||||
{
|
||||
|
||||
if arg < 0 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ 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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue