gonzui


Format: Advanced Search

t2ex/bsd_source/lib/libc/src_bsd/complex/s_cexp.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*      $OpenBSD: s_cexp.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: /*                                                      cexp()
   21:  *
   22:  *      Complex exponential function
   23:  *
   24:  *
   25:  *
   26:  * SYNOPSIS:
   27:  *
   28:  * double complex cexp ();
   29:  * double complex z, w;
   30:  *
   31:  * w = cexp (z);
   32:  *
   33:  *
   34:  *
   35:  * DESCRIPTION:
   36:  *
   37:  * Returns the exponential of the complex argument z
   38:  * into the complex result w.
   39:  *
   40:  * If
   41:  *     z = x + iy,
   42:  *     r = exp(x),
   43:  *
   44:  * then
   45:  *
   46:  *     w = r cos y + i r sin y.
   47:  *
   48:  *
   49:  * ACCURACY:
   50:  *
   51:  *                      Relative error:
   52:  * arithmetic   domain     # trials      peak         rms
   53:  *    DEC       -10,+10      8700       3.7e-17     1.1e-17
   54:  *    IEEE      -10,+10     30000       3.0e-16     8.7e-17
   55:  *
   56:  */
   57: 
   58: #include <sys/cdefs.h>
   59: #include <complex.h>
   60: #include <float.h>
   61: #include <math.h>
   62: 
   63: double complex
   64: cexp(double complex z)
   65: {
   66:         double complex w;
   67:         double r, x, y;
   68: 
   69:         x = creal (z);
   70:         y = cimag (z);
   71:         r = exp (x);
   72:         w = r * cos (y) + r * sin (y) * I;
   73:         return (w);
   74: }
   75: 
   76: #if     LDBL_MANT_DIG == 53
   77: #ifdef  lint
   78: /* PROTOLIB1 */
   79: long double complex cexpl(long double complex);
   80: #else   /* lint */
   81: __weak_alias(cexpl, cexp);
   82: #endif  /* lint */
   83: #endif  /* LDBL_MANT_DIG == 53 */