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