gitee.com/quant1x/num@v0.3.2/math32/sinhf.go (about) 1 package math32 2 3 func Sinh(x float32) float32 { 4 // The coefficients are #2029 from Hart & Cheney. (20.36D) 5 const ( 6 P0 = -0.6307673640497716991184787251e+6 7 P1 = -0.8991272022039509355398013511e+5 8 P2 = -0.2894211355989563807284660366e+4 9 P3 = -0.2630563213397497062819489e+2 10 Q0 = -0.6307673640497716991212077277e+6 11 Q1 = 0.1521517378790019070696485176e+5 12 Q2 = -0.173678953558233699533450911e+3 13 ) 14 15 sign := false 16 if x < 0 { 17 x = -x 18 sign = true 19 } 20 21 var temp float32 22 switch { 23 case x > 21: 24 temp = Exp(x) * 0.5 25 26 case x > 0.5: 27 ex := Exp(x) 28 temp = (ex - 1/ex) * 0.5 29 30 default: 31 sq := x * x 32 temp = (((P3*sq+P2)*sq+P1)*sq + P0) * x 33 temp = temp / (((sq+Q2)*sq+Q1)*sq + Q0) 34 } 35 36 if sign { 37 temp = -temp 38 } 39 return temp 40 }