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