gonzui


Format: Advanced Search

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

Search this content:

    1: /*      $OpenBSD: s_ccos.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: /*                                                      ccos()
   21:  *
   22:  *      Complex circular cosine
   23:  *
   24:  *
   25:  *
   26:  * SYNOPSIS:
   27:  *
   28:  * double complex ccos();
   29:  * double complex z, w;
   30:  *
   31:  * w = ccos (z);
   32:  *
   33:  *
   34:  *
   35:  * DESCRIPTION:
   36:  *
   37:  * If
   38:  *     z = x + iy,
   39:  *
   40:  * then
   41:  *
   42:  *     w = cos x  cosh y  -  i sin x sinh y.
   43:  *
   44:  *
   45:  *
   46:  * ACCURACY:
   47:  *
   48:  *                      Relative error:
   49:  * arithmetic   domain     # trials      peak         rms
   50:  *    DEC       -10,+10      8400       4.5e-17     1.3e-17
   51:  *    IEEE      -10,+10     30000       3.8e-16     1.0e-16
   52:  */
   53: 
   54: #include <sys/cdefs.h>
   55: #include <complex.h>
   56: #include <float.h>
   57: #include <math.h>
   58: 
   59: /* calculate cosh and sinh */
   60: 
   61: static void
   62: _cchsh(double x, double *c, double *s)
   63: {
   64:         double e, ei;
   65: 
   66:         if (fabs(x) <= 0.5) {
   67:                 *c = cosh(x);
   68:                 *s = sinh(x);
   69:         }
   70:         else {
   71:                 e = exp(x);
   72:                 ei = 0.5/e;
   73:                 e = 0.5 * e;
   74:                 *s = e - ei;
   75:                 *c = e + ei;
   76:         }
   77: }
   78: 
   79: double complex
   80: ccos(double complex z)
   81: {
   82:         double complex w;
   83:         double ch, sh;
   84: 
   85:         _cchsh( cimag(z), &ch, &sh );
   86:         w = cos(creal (z)) * ch - (sin (creal (z)) * sh) * I;
   87:         return (w);
   88: }
   89: 
   90: #if     LDBL_MANT_DIG == 53
   91: #ifdef  lint
   92: /* PROTOLIB1 */
   93: long double complex ccosl(long double complex);
   94: #else   /* lint */
   95: __weak_alias(ccosl, ccos);
   96: #endif  /* lint */
   97: #endif  /* LDBL_MANT_DIG == 53 */