blob: 144291079f97ca7042ea3eb894efa39646449612 [file] [log] [blame]
Elliott Hughesab528072018-07-24 00:01:52 +00001/*-
2 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* cpowf
18 *
19 * Complex power function
20 *
21 *
22 *
23 * SYNOPSIS:
24 *
25 * float complex cpowf();
26 * float complex a, z, w;
27 *
28 * w = cpowf (a, z);
29 *
30 *
31 *
32 * DESCRIPTION:
33 *
34 * Raises complex A to the complex Zth power.
35 * Definition is per AMS55 # 4.2.8,
36 * analytically equivalent to cpow(a,z) = cexp(z clog(a)).
37 *
38 * ACCURACY:
39 *
40 * Relative error:
41 * arithmetic domain # trials peak rms
42 * IEEE -10,+10 30000 9.4e-15 1.5e-15
43 *
44 */
45
Elliott Hughesab528072018-07-24 00:01:52 +000046#include <complex.h>
47#include <math.h>
Elliott Hughes2d1a2aa2019-02-04 13:43:48 -080048#include "math_private.h"
Elliott Hughesab528072018-07-24 00:01:52 +000049
50float complex
51cpowf(float complex a, float complex z)
52{
53 float complex w;
54 float x, y, r, theta, absa, arga;
55
56 x = crealf(z);
57 y = cimagf(z);
58 absa = cabsf (a);
59 if (absa == 0.0f) {
Elliott Hughes2d1a2aa2019-02-04 13:43:48 -080060 return (CMPLXF(0.0f, 0.0f));
Elliott Hughesab528072018-07-24 00:01:52 +000061 }
62 arga = cargf (a);
63 r = powf (absa, x);
64 theta = x * arga;
65 if (y != 0.0f) {
66 r = r * expf (-y * arga);
67 theta = theta + y * logf (absa);
68 }
Elliott Hughes2d1a2aa2019-02-04 13:43:48 -080069 w = CMPLXF(r * cosf (theta), r * sinf (theta));
Elliott Hughesab528072018-07-24 00:01:52 +000070 return (w);
71}