1*2f2c0062Sguenther /* $OpenBSD: s_cexp.c,v 1.7 2016/09/12 19:47:02 guenther Exp $ */
27b36286aSmartynas /*
37b36286aSmartynas * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
47b36286aSmartynas *
57b36286aSmartynas * Permission to use, copy, modify, and distribute this software for any
67b36286aSmartynas * purpose with or without fee is hereby granted, provided that the above
77b36286aSmartynas * copyright notice and this permission notice appear in all copies.
87b36286aSmartynas *
97b36286aSmartynas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
107b36286aSmartynas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
117b36286aSmartynas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
127b36286aSmartynas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
137b36286aSmartynas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
147b36286aSmartynas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
157b36286aSmartynas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
167b36286aSmartynas */
177b36286aSmartynas
187b36286aSmartynas /* cexp()
197b36286aSmartynas *
207b36286aSmartynas * Complex exponential function
217b36286aSmartynas *
227b36286aSmartynas *
237b36286aSmartynas *
247b36286aSmartynas * SYNOPSIS:
257b36286aSmartynas *
267b36286aSmartynas * double complex cexp ();
277b36286aSmartynas * double complex z, w;
287b36286aSmartynas *
297b36286aSmartynas * w = cexp (z);
307b36286aSmartynas *
317b36286aSmartynas *
327b36286aSmartynas *
337b36286aSmartynas * DESCRIPTION:
347b36286aSmartynas *
357b36286aSmartynas * Returns the exponential of the complex argument z
367b36286aSmartynas * into the complex result w.
377b36286aSmartynas *
387b36286aSmartynas * If
397b36286aSmartynas * z = x + iy,
407b36286aSmartynas * r = exp(x),
417b36286aSmartynas *
427b36286aSmartynas * then
437b36286aSmartynas *
447b36286aSmartynas * w = r cos y + i r sin y.
457b36286aSmartynas *
467b36286aSmartynas *
477b36286aSmartynas * ACCURACY:
487b36286aSmartynas *
497b36286aSmartynas * Relative error:
507b36286aSmartynas * arithmetic domain # trials peak rms
517b36286aSmartynas * DEC -10,+10 8700 3.7e-17 1.1e-17
527b36286aSmartynas * IEEE -10,+10 30000 3.0e-16 8.7e-17
537b36286aSmartynas *
547b36286aSmartynas */
557b36286aSmartynas
567b36286aSmartynas #include <complex.h>
57de3697aaSmartynas #include <float.h>
587b36286aSmartynas #include <math.h>
597b36286aSmartynas
607b36286aSmartynas double complex
cexp(double complex z)617b36286aSmartynas cexp(double complex z)
627b36286aSmartynas {
637b36286aSmartynas double complex w;
647b36286aSmartynas double r, x, y;
657b36286aSmartynas
667b36286aSmartynas x = creal (z);
677b36286aSmartynas y = cimag (z);
687b36286aSmartynas r = exp (x);
697b36286aSmartynas w = r * cos (y) + r * sin (y) * I;
707b36286aSmartynas return (w);
717b36286aSmartynas }
72*2f2c0062Sguenther DEF_STD(cexp);
73*2f2c0062Sguenther LDBL_MAYBE_UNUSED_CLONE(cexp);
74