...
Source file src/pkg/math/sinh.go
1
2
3
4
5 package math
6
7
18
19
20
21
22
23
24
25 func Sinh(x float64) float64
26
27 func sinh(x float64) float64 {
28
29 const (
30 P0 = -0.6307673640497716991184787251e+6
31 P1 = -0.8991272022039509355398013511e+5
32 P2 = -0.2894211355989563807284660366e+4
33 P3 = -0.2630563213397497062819489e+2
34 Q0 = -0.6307673640497716991212077277e+6
35 Q1 = 0.1521517378790019070696485176e+5
36 Q2 = -0.173678953558233699533450911e+3
37 )
38
39 sign := false
40 if x < 0 {
41 x = -x
42 sign = true
43 }
44
45 var temp float64
46 switch {
47 case x > 21:
48 temp = Exp(x) * 0.5
49
50 case x > 0.5:
51 ex := Exp(x)
52 temp = (ex - 1/ex) * 0.5
53
54 default:
55 sq := x * x
56 temp = (((P3*sq+P2)*sq+P1)*sq + P0) * x
57 temp = temp / (((sq+Q2)*sq+Q1)*sq + Q0)
58 }
59
60 if sign {
61 temp = -temp
62 }
63 return temp
64 }
65
66
67
68
69
70
71
72 func Cosh(x float64) float64
73
74 func cosh(x float64) float64 {
75 x = Abs(x)
76 if x > 21 {
77 return Exp(x) * 0.5
78 }
79 ex := Exp(x)
80 return (ex + 1/ex) * 0.5
81 }
82
View as plain text