1
0
mirror of https://github.com/golang/go synced 2024-11-19 01:34:40 -07:00
go/test/math.go
Russ Cox 72e3b204e4 add gobuild.
use gobuild-generated Makefile for math and os.
other makefile tweaks.
move math/main.go to test/math.go

R=r
OCL=15529
CL=15537
2008-09-19 11:55:46 -07:00

208 lines
5.4 KiB
Go

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import math "math"
const length = 10;
var
(
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 ck(a,b float64);
func
main()
{
for i:=0; i<length; i++ {
f := vf[i];
ck(asin[i], math.asin(f/10));
ck(atan[i], math.atan(f));
ck(exp[i], math.exp(f));
ck(floor[i], math.floor(f));
ck(log[i], math.log(math.fabs(f)));
ck(pow[i], math.pow(10, f));
ck(sin[i], math.sin(f));
ck(sinh[i], math.sinh(f));
ck(sqrt[i], math.sqrt(math.fabs(f)));
ck(tan[i], math.tan(f));
ck(tanh[i], math.tanh(f));
ck(math.fabs(tanh[i]*math.sqrt(2)),
math.hypot(tanh[i], tanh[i]));
}
}
func
ck(a,b float64)
{
d := a-b;
if d < 0 {
d = -d;
}
e := 1e-14;
if a != 0 {
e = e*a;
if e < 0 {
e = -e;
}
}
if d > e {
panic(a, " ", b, "\n");
}
}
func
init()
{
vf[0] = 4.9790119248836735e+00;
vf[1] = 7.7388724745781045e+00;
vf[2] = -2.7688005719200159e-01;
vf[3] = -5.0106036182710749e+00;
vf[4] = 9.6362937071984173e+00;
vf[5] = 2.9263772392439646e+00;
vf[6] = 5.2290834314593066e+00;
vf[7] = 2.7279399104360102e+00;
vf[8] = 1.8253080916808550e+00;
vf[9] = -8.6859247685756013e+00;
asin[0] = 5.2117697218417440e-01;
asin[1] = 8.8495619865825236e-01;
asin[2] = -2.7691544662819413e-02;
asin[3] = -5.2482360935268932e-01;
asin[4] = 1.3002662421166553e+00;
asin[5] = 2.9698415875871901e-01;
asin[6] = 5.5025938468083364e-01;
asin[7] = 2.7629597861677200e-01;
asin[8] = 1.8355989225745148e-01;
asin[9] = -1.0523547536021498e+00;
atan[0] = 1.3725902621296217e+00;
atan[1] = 1.4422906096452980e+00;
atan[2] = -2.7011324359471755e-01;
atan[3] = -1.3738077684543379e+00;
atan[4] = 1.4673921193587666e+00;
atan[5] = 1.2415173565870167e+00;
atan[6] = 1.3818396865615167e+00;
atan[7] = 1.2194305844639670e+00;
atan[8] = 1.0696031952318783e+00;
atan[9] = -1.4561721938838085e+00;
exp[0] = 1.4533071302642137e+02;
exp[1] = 2.2958822575694450e+03;
exp[2] = 7.5814542574851664e-01;
exp[3] = 6.6668778421791010e-03;
exp[4] = 1.5310493273896035e+04;
exp[5] = 1.8659907517999329e+01;
exp[6] = 1.8662167355098713e+02;
exp[7] = 1.5301332413189379e+01;
exp[8] = 6.2047063430646876e+00;
exp[9] = 1.6894712385826522e-04;
floor[0] = 4.0000000000000000e+00;
floor[1] = 7.0000000000000000e+00;
floor[2] = -1.0000000000000000e+00;
floor[3] = -6.0000000000000000e+00;
floor[4] = 9.0000000000000000e+00;
floor[5] = 2.0000000000000000e+00;
floor[6] = 5.0000000000000000e+00;
floor[7] = 2.0000000000000000e+00;
floor[8] = 1.0000000000000000e+00;
floor[9] = -9.0000000000000000e+00;
log[0] = 1.6052314626930630e+00;
log[1] = 2.0462560018708768e+00;
log[2] = -1.2841708730962657e+00;
log[3] = 1.6115563905281544e+00;
log[4] = 2.2655365644872018e+00;
log[5] = 1.0737652208918380e+00;
log[6] = 1.6542360106073545e+00;
log[7] = 1.0035467127723465e+00;
log[8] = 6.0174879014578053e-01;
log[9] = 2.1617038728473527e+00;
pow[0] = 9.5282232631648415e+04;
pow[1] = 5.4811599352999900e+07;
pow[2] = 5.2859121715894400e-01;
pow[3] = 9.7587991957286472e-06;
pow[4] = 4.3280643293460450e+09;
pow[5] = 8.4406761805034551e+02;
pow[6] = 1.6946633276191194e+05;
pow[7] = 5.3449040147551940e+02;
pow[8] = 6.6881821384514159e+01;
pow[9] = 2.0609869004248744e-09;
sin[0] = -9.6466616586009283e-01;
sin[1] = 9.9338225271646543e-01;
sin[2] = -2.7335587039794395e-01;
sin[3] = 9.5586257685042800e-01;
sin[4] = -2.0994210667799692e-01;
sin[5] = 2.1355787807998605e-01;
sin[6] = -8.6945689711673619e-01;
sin[7] = 4.0195666811555783e-01;
sin[8] = 9.6778633541688000e-01;
sin[9] = -6.7344058690503452e-01;
sinh[0] = 7.2661916084208533e+01;
sinh[1] = 1.1479409110035194e+03;
sinh[2] = -2.8043136512812520e-01;
sinh[3] = -7.4994290911815868e+01;
sinh[4] = 7.6552466042906761e+03;
sinh[5] = 9.3031583421672010e+00;
sinh[6] = 9.3308157558281088e+01;
sinh[7] = 7.6179893137269143e+00;
sinh[8] = 3.0217691805496156e+00;
sinh[9] = -2.9595057572444951e+03;
sqrt[0] = 2.2313699659365484e+00;
sqrt[1] = 2.7818829009464263e+00;
sqrt[2] = 5.2619393496314792e-01;
sqrt[3] = 2.2384377628763938e+00;
sqrt[4] = 3.1042380236055380e+00;
sqrt[5] = 1.7106657298385224e+00;
sqrt[6] = 2.2867189227054791e+00;
sqrt[7] = 1.6516476350711160e+00;
sqrt[8] = 1.3510396336454586e+00;
sqrt[9] = 2.9471892997524950e+00;
tan[0] = -3.6613165650402277e+00;
tan[1] = 8.6490023264859754e+00;
tan[2] = -2.8417941955033615e-01;
tan[3] = 3.2532901859747287e+00;
tan[4] = 2.1472756403802937e-01;
tan[5] = -2.1860091071106700e-01;
tan[6] = -1.7600028178723679e+00;
tan[7] = -4.3898089147528178e-01;
tan[8] = -3.8438855602011305e+00;
tan[9] = 9.1098879337768517e-01;
tanh[0] = 9.9990531206936328e-01;
tanh[1] = 9.9999962057085307e-01;
tanh[2] = -2.7001505097318680e-01;
tanh[3] = -9.9991110943061700e-01;
tanh[4] = 9.9999999146798441e-01;
tanh[5] = 9.9427249436125233e-01;
tanh[6] = 9.9994257600983156e-01;
tanh[7] = 9.9149409509772863e-01;
tanh[8] = 9.4936501296239700e-01;
tanh[9] = -9.9999994291374019e-01;
}