1
2
3
4
5 package math
6
7 8 9 10 11 12 13 14 15 16 17
18
19
20 func Sinh(x float64) float64 {
21
22 const (
23 P0 = -0.6307673640497716991184787251e+6
24 P1 = -0.8991272022039509355398013511e+5
25 P2 = -0.2894211355989563807284660366e+4
26 P3 = -0.2630563213397497062819489e+2
27 Q0 = -0.6307673640497716991212077277e+6
28 Q1 = 0.1521517378790019070696485176e+5
29 Q2 = -0.173678953558233699533450911e+3
30 )
31
32 sign := false
33 if x < 0 {
34 x = -x
35 sign = true
36 }
37
38 var temp float64
39 switch true {
40 case x > 21:
41 temp = Exp(x) / 2
42
43 case x > 0.5:
44 temp = (Exp(x) - Exp(-x)) / 2
45
46 default:
47 sq := x * x
48 temp = (((P3*sq+P2)*sq+P1)*sq + P0) * x
49 temp = temp / (((sq+Q2)*sq+Q1)*sq + Q0)
50 }
51
52 if sign {
53 temp = -temp
54 }
55 return temp
56 }
57
58
59 func Cosh(x float64) float64 {
60 if x < 0 {
61 x = -x
62 }
63 if x > 21 {
64 return Exp(x) / 2
65 }
66 return (Exp(x) + Exp(-x)) / 2
67 }