gonzui


Format: Advanced Search

t2ex/bsd_source/lib/libc/src_bsd/complex/s_clog.cbare sourcepermlink (0.00 seconds)

Search this content:

    1: /*      $OpenBSD: s_clog.c,v 1.2 2011/07/08 19:25:31 martynas Exp $  */
    2: /*
    3:  * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
    4:  *
    5:  * Permission to use, copy, modify, and distribute this software for any
    6:  * purpose with or without fee is hereby granted, provided that the above
    7:  * copyright notice and this permission notice appear in all copies.
    8:  *
    9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   16:  */
   17: 
   18: /* LINTLIBRARY */
   19: 
   20: /*                                                      clog.c
   21:  *
   22:  *      Complex natural logarithm
   23:  *
   24:  *
   25:  *
   26:  * SYNOPSIS:
   27:  *
   28:  * double complex clog();
   29:  * double complex z, w;
   30:  *
   31:  * w = clog (z);
   32:  *
   33:  *
   34:  *
   35:  * DESCRIPTION:
   36:  *
   37:  * Returns complex logarithm to the base e (2.718...) of
   38:  * the complex argument x.
   39:  *
   40:  * If z = x + iy, r = sqrt( x**2 + y**2 ),
   41:  * then
   42:  *       w = log(r) + i arctan(y/x).
   43:  * 
   44:  * The arctangent ranges from -PI to +PI.
   45:  *
   46:  *
   47:  * ACCURACY:
   48:  *
   49:  *                      Relative error:
   50:  * arithmetic   domain     # trials      peak         rms
   51:  *    DEC       -10,+10      7000       8.5e-17     1.9e-17
   52:  *    IEEE      -10,+10     30000       5.0e-15     1.1e-16
   53:  *
   54:  * Larger relative error can be observed for z near 1 +i0.
   55:  * In IEEE arithmetic the peak absolute error is 5.2e-16, rms
   56:  * absolute error 1.0e-16.
   57:  */
   58: 
   59: #include <sys/cdefs.h>
   60: #include <complex.h>
   61: #include <float.h>
   62: #include <math.h>
   63: 
   64: double complex
   65: clog(double complex z)
   66: {
   67:         double complex w;
   68:         double p, rr;
   69: 
   70:         /*rr = sqrt( z->r * z->r  +  z->i * z->i );*/
   71:         rr = cabs(z);
   72:         p = log(rr);
   73:         rr = atan2 (cimag (z), creal (z));
   74:         w = p + rr * I;
   75:         return (w);
   76: }
   77: 
   78: #if     LDBL_MANT_DIG == 53
   79: #ifdef  lint
   80: /* PROTOLIB1 */
   81: long double complex clogl(long double complex);
   82: #else   /* lint */
   83: __weak_alias(clogl, clog);
   84: #endif  /* lint */
   85: #endif  /* LDBL_MANT_DIG == 53 */