// Copyright 2010 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package cmplximport// The original C code, the long comment, and the constants// below are from http://netlib.sandia.gov/cephes/c9x-complex/clog.c.// The go code is a simplified version of the original C.//// Cephes Math Library Release 2.8: June, 2000// Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier//// The readme file at http://netlib.sandia.gov/cephes/ says:// Some software in this archive may be from the book _Methods and// Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster// International, 1989) or from the Cephes Mathematical Library, a// commercial product. In either event, it is copyrighted by the author.// What you see here may be used freely but it comes with no support or// guarantee.//// The two known misprints in the book are repaired here in the// source listings for the gamma function and the incomplete beta// integral.//// Stephen L. Moshier// moshier@na-net.ornl.gov// Complex circular arc sine//// DESCRIPTION://// Inverse complex sine:// 2// w = -i clog( iz + csqrt( 1 - z ) ).//// casin(z) = -i casinh(iz)//// ACCURACY://// Relative error:// arithmetic domain # trials peak rms// DEC -10,+10 10100 2.1e-15 3.4e-16// IEEE -10,+10 30000 2.2e-14 2.7e-15// Larger relative error can be observed for z near zero.// Also tested by csin(casin(z)) = z.// Asin returns the inverse sine of x.func ( complex128) complex128 {switch , := real(), imag(); {case == 0 && math.Abs() <= 1:returncomplex(math.Asin(), )case == 0 && math.Abs() <= 1:returncomplex(, math.Asinh())casemath.IsNaN():switch {case == 0:returncomplex(, math.NaN())casemath.IsInf(, 0):returncomplex(math.NaN(), )default:returnNaN() }casemath.IsInf(, 0):switch {casemath.IsNaN():returncasemath.IsInf(, 0):returncomplex(math.Copysign(math.Pi/4, ), )default:returncomplex(math.Copysign(0, ), ) }casemath.IsInf(, 0):returncomplex(math.Copysign(math.Pi/2, ), math.Copysign(, )) } := complex(-imag(), real()) // i * x := * := complex(1-real(), -imag()) // 1 - x*x := Sqrt() // x2 = sqrt(1 - x*x) := Log( + )returncomplex(imag(), -real()) // -i * w}// Asinh returns the inverse hyperbolic sine of x.func ( complex128) complex128 {switch , := real(), imag(); {case == 0 && math.Abs() <= 1:returncomplex(math.Asinh(), )case == 0 && math.Abs() <= 1:returncomplex(, math.Asin())casemath.IsInf(, 0):switch {casemath.IsInf(, 0):returncomplex(, math.Copysign(math.Pi/4, ))casemath.IsNaN():returndefault:returncomplex(, math.Copysign(0.0, )) }casemath.IsNaN():switch {case == 0:returncasemath.IsInf(, 0):returncomplex(, )default:returnNaN() }casemath.IsInf(, 0):returncomplex(math.Copysign(, ), math.Copysign(math.Pi/2, )) } := * := complex(1+real(), imag()) // 1 + x*xreturnLog( + Sqrt()) // log(x + sqrt(1 + x*x))}// Complex circular arc cosine//// DESCRIPTION://// w = arccos z = PI/2 - arcsin z.//// ACCURACY://// Relative error:// arithmetic domain # trials peak rms// DEC -10,+10 5200 1.6e-15 2.8e-16// IEEE -10,+10 30000 1.8e-14 2.2e-15// Acos returns the inverse cosine of x.func ( complex128) complex128 { := Asin()returncomplex(math.Pi/2-real(), -imag())}// Acosh returns the inverse hyperbolic cosine of x.func ( complex128) complex128 {if == 0 {returncomplex(0, math.Copysign(math.Pi/2, imag())) } := Acos()ifimag() <= 0 {returncomplex(-imag(), real()) // i * w }returncomplex(imag(), -real()) // -i * w}// Complex circular arc tangent//// DESCRIPTION://// If// z = x + iy,//// then// 1 ( 2x )// Re w = - arctan(-----------) + k PI// 2 ( 2 2)// (1 - x - y )//// ( 2 2)// 1 (x + (y+1) )// Im w = - log(------------)// 4 ( 2 2)// (x + (y-1) )//// Where k is an arbitrary integer.//// catan(z) = -i catanh(iz).//// ACCURACY://// Relative error:// arithmetic domain # trials peak rms// DEC -10,+10 5900 1.3e-16 7.8e-18// IEEE -10,+10 30000 2.3e-15 8.5e-17// The check catan( ctan(z) ) = z, with |x| and |y| < PI/2,// had peak relative error 1.5e-16, rms relative error// 2.9e-17. See also clog().// Atan returns the inverse tangent of x.func ( complex128) complex128 {switch , := real(), imag(); {case == 0:returncomplex(math.Atan(), )case == 0 && math.Abs() <= 1:returncomplex(, math.Atanh())casemath.IsInf(, 0) || math.IsInf(, 0):ifmath.IsNaN() {returncomplex(math.NaN(), math.Copysign(0, )) }returncomplex(math.Copysign(math.Pi/2, ), math.Copysign(0, ))casemath.IsNaN() || math.IsNaN():returnNaN() } := real() * real() := 1 - - imag()*imag()if == 0 {returnNaN() } := 0.5 * math.Atan2(2*real(), ) := reducePi() = imag() - 1 := + *if == 0 {returnNaN() } = imag() + 1 := ( + *) / returncomplex(, 0.25*math.Log())}// Atanh returns the inverse hyperbolic tangent of x.func ( complex128) complex128 { := complex(-imag(), real()) // z = i * x = Atan()returncomplex(imag(), -real()) // z = -i * z}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.