// 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 sine//// DESCRIPTION://// If// z = x + iy,//// then//// w = sin x cosh y + i cos x sinh y.//// csin(z) = -i csinh(iz).//// ACCURACY://// Relative error:// arithmetic domain # trials peak rms// DEC -10,+10 8400 5.3e-17 1.3e-17// IEEE -10,+10 30000 3.8e-16 1.0e-16// Also tested by csin(casin(z)) = z.// Sin returns the sine of x.func ( complex128) complex128 {switch , := real(), imag(); {case == 0 && (math.IsInf(, 0) || math.IsNaN()):returncomplex(math.NaN(), )casemath.IsInf(, 0):switch {case == 0:returncasemath.IsInf(, 0) || math.IsNaN():returncomplex(math.NaN(), ) }case == 0 && math.IsNaN():return } , := math.Sincos(real()) , := sinhcosh(imag())returncomplex(*, *)}// Complex hyperbolic sine//// DESCRIPTION://// csinh z = (cexp(z) - cexp(-z))/2// = sinh x * cos y + i cosh x * sin y .//// ACCURACY://// Relative error:// arithmetic domain # trials peak rms// IEEE -10,+10 30000 3.1e-16 8.2e-17// Sinh returns the hyperbolic sine of x.func ( complex128) complex128 {switch , := real(), imag(); {case == 0 && (math.IsInf(, 0) || math.IsNaN()):returncomplex(, math.NaN())casemath.IsInf(, 0):switch {case == 0:returncomplex(, )casemath.IsInf(, 0) || math.IsNaN():returncomplex(, math.NaN()) }case == 0 && math.IsNaN():returncomplex(math.NaN(), ) } , := math.Sincos(imag()) , := sinhcosh(real())returncomplex(*, *)}// Complex circular cosine//// DESCRIPTION://// If// z = x + iy,//// then//// w = cos x cosh y - i sin x sinh y.//// ACCURACY://// Relative error:// arithmetic domain # trials peak rms// DEC -10,+10 8400 4.5e-17 1.3e-17// IEEE -10,+10 30000 3.8e-16 1.0e-16// Cos returns the cosine of x.func ( complex128) complex128 {switch , := real(), imag(); {case == 0 && (math.IsInf(, 0) || math.IsNaN()):returncomplex(math.NaN(), -*math.Copysign(0, ))casemath.IsInf(, 0):switch {case == 0:returncomplex(math.Inf(1), -*math.Copysign(0, ))casemath.IsInf(, 0) || math.IsNaN():returncomplex(math.Inf(1), math.NaN()) }case == 0 && math.IsNaN():returncomplex(math.NaN(), 0) } , := math.Sincos(real()) , := sinhcosh(imag())returncomplex(*, -*)}// Complex hyperbolic cosine//// DESCRIPTION://// ccosh(z) = cosh x cos y + i sinh x sin y .//// ACCURACY://// Relative error:// arithmetic domain # trials peak rms// IEEE -10,+10 30000 2.9e-16 8.1e-17// Cosh returns the hyperbolic cosine of x.func ( complex128) complex128 {switch , := real(), imag(); {case == 0 && (math.IsInf(, 0) || math.IsNaN()):returncomplex(math.NaN(), *math.Copysign(0, ))casemath.IsInf(, 0):switch {case == 0:returncomplex(math.Inf(1), *math.Copysign(0, ))casemath.IsInf(, 0) || math.IsNaN():returncomplex(math.Inf(1), math.NaN()) }case == 0 && math.IsNaN():returncomplex(math.NaN(), ) } , := math.Sincos(imag()) , := sinhcosh(real())returncomplex(*, *)}// calculate sinh and cosh.func sinhcosh( float64) (, float64) {ifmath.Abs() <= 0.5 {returnmath.Sinh(), math.Cosh() } := math.Exp() := 0.5 / *= 0.5return - , + }
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.