Source file src/pkg/math/tanh.go
1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package math 6 7 /* 8 Floating-point hyperbolic tangent. 9 10 Sinh and Cosh are called except for large arguments, which 11 would cause overflow improperly. 12 */ 13 14 // Tanh computes the hyperbolic tangent of x. 15 func Tanh(x float64) float64 { 16 if x < 0 { 17 x = -x 18 if x > 21 { 19 return -1 20 } 21 return -Sinh(x) / Cosh(x) 22 } 23 if x > 21 { 24 return 1 25 } 26 return Sinh(x) / Cosh(x) 27 }