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;
}
func
-acos(arg double)double
+acos(arg float64)float64
{
if(arg > 1 || arg < -1) {
return sys.NaN();
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)
*/
)
/*
- 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);
}
/*
- 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 {
}
/*
- 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 {
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
(
)
func
-atan2(arg1, arg2 double) double
+atan2(arg1, arg2 float64) float64
{
- var x double;
+ var x float64;
if arg1+arg2 == arg1 {
if arg1 >= 0 {
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
(
)
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)
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;
export fabs
func
-fabs(arg double) double
+fabs(arg float64) float64
{
if arg < 0 {
*/
func
-floor(arg double) double
+floor(arg float64) float64
{
- var fract, d double;
+ var fract, d float64;
d = arg;
if d < 0 {
}
func
-ceil(arg double) double
+ceil(arg float64) float64
{
return -floor(-arg);
}
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 {
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;
q = q/p;
r = q;
p = 1;
- for ;; {
+ for {
r = r*r;
s = r+4;
if s == 4 {
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
(
)
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 {
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 {
package main
//import math "math"
-//////////////////
+
import math "asin"
import math "atan"
import math "atan2"
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()
}
func
-ck(a,b double)
+ck(a,b float64)
{
d := a-b;
if d < 0 {
*/
func
-pow(arg1,arg2 double) double
+pow(arg1,arg2 float64) float64
{
- var temp double;
+ var temp float64;
var l long;
if arg2 < 0 {
if l&1 != 0 {
temp = temp*arg1;
}
- l = l>>1;
+ l >>= 1;
if l == 0 {
return temp;
}
- arg1 = arg1*arg1;
+ arg1 *= arg1;
}
}
* 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,
// 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();
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];
}
}
)
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;
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;
}
}
func
-cos(arg double) double
+cos(arg float64) float64
{
if arg < 0 {
arg = -arg;
}
func
-sin(arg double) double
+sin(arg float64) float64
{
return sinus(arg, 0);
}
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
)
func
-sinh(arg double) double
+sinh(arg float64) float64
{
- var temp, argsq double;
+ var temp, argsq float64;
var sign bool;
sign = false;
arg = -arg;
sign = true;
}
+
switch true {
case arg > 21:
temp = exp(arg)/2;
}
func
-cosh(arg double) double
+cosh(arg float64) float64
{
if arg < 0 {
arg = - arg;
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) {
if arg <= 0 {
if arg < 0 {
- panic "return sys.NaN()"
+ return sys.NaN();
}
return 0;
}
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 {
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
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
)
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;
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;