1
// Copyright 2010 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.
9
// The original C code, the long comment, and the constants
10
// below are from http://netlib.sandia.gov/cephes/c9x-complex/clog.c.
11
// The go code is a simplified version of the original C.
13
// Cephes Math Library Release 2.8: June, 2000
14
// Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
16
// The readme file at http://netlib.sandia.gov/cephes/ says:
17
// Some software in this archive may be from the book _Methods and
18
// Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster
19
// International, 1989) or from the Cephes Mathematical Library, a
20
// commercial product. In either event, it is copyrighted by the author.
21
// What you see here may be used freely but it comes with no support or
24
// The two known misprints in the book are repaired here in the
25
// source listings for the gamma function and the incomplete beta
29
// moshier@na-net.ornl.gov
31
// Complex circular sine
40
// w = sin x cosh y + i cos x sinh y.
42
// csin(z) = -i csinh(iz).
47
// arithmetic domain # trials peak rms
48
// DEC -10,+10 8400 5.3e-17 1.3e-17
49
// IEEE -10,+10 30000 3.8e-16 1.0e-16
50
// Also tested by csin(casin(z)) = z.
52
// Sin returns the sine of x.
53
func Sin(x complex128) complex128 {
54
s, c := math.Sincos(real(x))
55
sh, ch := sinhcosh(imag(x))
56
return complex(s*ch, c*sh)
59
// Complex hyperbolic sine
63
// csinh z = (cexp(z) - cexp(-z))/2
64
// = sinh x * cos y + i cosh x * sin y .
69
// arithmetic domain # trials peak rms
70
// IEEE -10,+10 30000 3.1e-16 8.2e-17
72
// Sinh returns the hyperbolic sine of x.
73
func Sinh(x complex128) complex128 {
74
s, c := math.Sincos(imag(x))
75
sh, ch := sinhcosh(real(x))
76
return complex(c*sh, s*ch)
79
// Complex circular cosine
88
// w = cos x cosh y - i sin x sinh y.
93
// arithmetic domain # trials peak rms
94
// DEC -10,+10 8400 4.5e-17 1.3e-17
95
// IEEE -10,+10 30000 3.8e-16 1.0e-16
97
// Cos returns the cosine of x.
98
func Cos(x complex128) complex128 {
99
s, c := math.Sincos(real(x))
100
sh, ch := sinhcosh(imag(x))
101
return complex(c*ch, -s*sh)
104
// Complex hyperbolic cosine
108
// ccosh(z) = cosh x cos y + i sinh x sin y .
113
// arithmetic domain # trials peak rms
114
// IEEE -10,+10 30000 2.9e-16 8.1e-17
116
// Cosh returns the hyperbolic cosine of x.
117
func Cosh(x complex128) complex128 {
118
s, c := math.Sincos(imag(x))
119
sh, ch := sinhcosh(real(x))
120
return complex(c*ch, s*sh)
123
// calculate sinh and cosh
124
func sinhcosh(x float64) (sh, ch float64) {
125
if math.Fabs(x) <= 0.5 {
126
return math.Sinh(x), math.Cosh(x)
131
return e - ei, e + ei