Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
sinh.go94 linesDownload Raw Back to math
1// Copyright 2009 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4 5package math6 7/*8	Floating-point hyperbolic sine and cosine.9 10	The exponential func is called for arguments11	greater in magnitude than 0.5.12 13	A series is used for arguments smaller in magnitude than 0.5.14 15	Cosh(x) is computed from the exponential func for16	all arguments.17*/18 19// Sinh returns the hyperbolic sine of x.20//21// Special cases are:22//23//	Sinh(±0) = ±024//	Sinh(±Inf) = ±Inf25//	Sinh(NaN) = NaN26func Sinh(x float64) float64 {27	if haveArchSinh {28		return archSinh(x)29	}30	return sinh(x)31}32 33func sinh(x float64) float64 {34	// The coefficients are #2029 from Hart & Cheney. (20.36D)35	const (36		P0 = -0.6307673640497716991184787251e+637		P1 = -0.8991272022039509355398013511e+538		P2 = -0.2894211355989563807284660366e+439		P3 = -0.2630563213397497062819489e+240		Q0 = -0.6307673640497716991212077277e+641		Q1 = 0.1521517378790019070696485176e+542		Q2 = -0.173678953558233699533450911e+343	)44 45	sign := false46	if x < 0 {47		x = -x48		sign = true49	}50 51	var temp float6452	switch {53	case x > 21:54		temp = Exp(x) * 0.555 56	case x > 0.5:57		ex := Exp(x)58		temp = (ex - 1/ex) * 0.559 60	default:61		sq := x * x62		temp = (((P3*sq+P2)*sq+P1)*sq + P0) * x63		temp = temp / (((sq+Q2)*sq+Q1)*sq + Q0)64	}65 66	if sign {67		temp = -temp68	}69	return temp70}71 72// Cosh returns the hyperbolic cosine of x.73//74// Special cases are:75//76//	Cosh(±0) = 177//	Cosh(±Inf) = +Inf78//	Cosh(NaN) = NaN79func Cosh(x float64) float64 {80	if haveArchCosh {81		return archCosh(x)82	}83	return cosh(x)84}85 86func cosh(x float64) float64 {87	x = Abs(x)88	if x > 21 {89		return Exp(x) * 0.590	}91	ex := Exp(x)92	return (ex + 1/ex) * 0.593}94 
codekingpro/portable-devtools · Team Ai