github.com/MangoDowner/go-gm@v0.0.0-20180818020936-8baa2bd4408c/src/math/cmplx/log.go (about)

     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.
     4  
     5  package cmplx
     6  
     7  import "math"
     8  
     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.
    12  //
    13  // Cephes Math Library Release 2.8:  June, 2000
    14  // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
    15  //
    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
    22  // guarantee.
    23  //
    24  //   The two known misprints in the book are repaired here in the
    25  // source listings for the gamma function and the incomplete beta
    26  // integral.
    27  //
    28  //   Stephen L. Moshier
    29  //   moshier@na-net.ornl.gov
    30  
    31  // Complex natural logarithm
    32  //
    33  // DESCRIPTION:
    34  //
    35  // Returns complex logarithm to the base e (2.718...) of
    36  // the complex argument z.
    37  //
    38  // If
    39  //       z = x + iy, r = sqrt( x**2 + y**2 ),
    40  // then
    41  //       w = log(r) + i arctan(y/x).
    42  //
    43  // The arctangent ranges from -PI to +PI.
    44  //
    45  // ACCURACY:
    46  //
    47  //                      Relative error:
    48  // arithmetic   domain     # trials      peak         rms
    49  //    DEC       -10,+10      7000       8.5e-17     1.9e-17
    50  //    IEEE      -10,+10     30000       5.0e-15     1.1e-16
    51  //
    52  // Larger relative error can be observed for z near 1 +i0.
    53  // In IEEE arithmetic the peak absolute error is 5.2e-16, rms
    54  // absolute error 1.0e-16.
    55  
    56  // Log returns the natural logarithm of x.
    57  func Log(x complex128) complex128 {
    58  	return complex(math.Log(Abs(x)), Phase(x))
    59  }
    60  
    61  // Log10 returns the decimal logarithm of x.
    62  func Log10(x complex128) complex128 {
    63  	return math.Log10E * Log(x)
    64  }