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