Skip to content

Commit 29af332

Browse files
committed
Add cpow from OpenBSD
Use clang by default on Darwin Enable cpow tests Fix #22
1 parent 0cd232d commit 29af332

5 files changed

Lines changed: 226 additions & 1 deletion

File tree

Make.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ FFLAGS += -O3
88
USEGCC = 1
99
USECLANG = 0
1010

11+
ifeq ($(OS), Darwin)
12+
USEGCC = 0
13+
USECLANG = 1
14+
endif
15+
16+
AR = ar
1117

1218
ifeq ($(USECLANG),1)
1319
USEGCC = 0
@@ -19,7 +25,6 @@ ifeq ($(USEGCC),1)
1925
CC = gcc
2026
CFLAGS_add += -fno-gnu89-inline
2127
endif
22-
AR = ar
2328

2429
ARCH := $(shell $(CC) -dumpmachine | sed "s/\([^-]*\).*$$/\1/")
2530
ifeq ($(ARCH),mingw32)

src/Make.files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ $(CUR_SRCS) = \
3030
s_scalbln.c s_scalbn.c s_scalbnf.c s_signbit.c \
3131
s_signgam.c s_significand.c s_significandf.c s_sin.c s_sinf.c \
3232
s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_tgammaf.c s_trunc.c s_truncf.c \
33+
s_cpow.c s_cpowf.c s_cpowl.c \
3334
w_cabs.c w_cabsf.c w_drem.c w_dremf.c
3435

3536
ifneq ($(OS), WINNT)

src/s_cpow.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* $OpenBSD: s_cpow.c,v 1.6 2013/07/03 04:46:36 espie 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+
/* cpow
19+
*
20+
* Complex power function
21+
*
22+
*
23+
*
24+
* SYNOPSIS:
25+
*
26+
* double complex cpow();
27+
* double complex a, z, w;
28+
*
29+
* w = cpow (a, z);
30+
*
31+
*
32+
*
33+
* DESCRIPTION:
34+
*
35+
* Raises complex A to the complex Zth power.
36+
* Definition is per AMS55 # 4.2.8,
37+
* analytically equivalent to cpow(a,z) = cexp(z clog(a)).
38+
*
39+
* ACCURACY:
40+
*
41+
* Relative error:
42+
* arithmetic domain # trials peak rms
43+
* IEEE -10,+10 30000 9.4e-15 1.5e-15
44+
*
45+
*/
46+
47+
#include <complex.h>
48+
#include <float.h>
49+
#include <math.h>
50+
51+
double complex
52+
cpow(double complex a, double complex z)
53+
{
54+
double complex w;
55+
double x, y, r, theta, absa, arga;
56+
57+
x = creal (z);
58+
y = cimag (z);
59+
absa = cabs (a);
60+
if (absa == 0.0) {
61+
return (0.0 + 0.0 * I);
62+
}
63+
arga = carg (a);
64+
r = pow (absa, x);
65+
theta = x * arga;
66+
if (y != 0.0) {
67+
r = r * exp (-y * arga);
68+
theta = theta + y * log (absa);
69+
}
70+
w = r * cos (theta) + (r * sin (theta)) * I;
71+
return (w);
72+
}
73+
74+
#if LDBL_MANT_DIG == DBL_MANT_DIG
75+
__strong_alias(cpowl, cpow);
76+
#endif /* LDBL_MANT_DIG == DBL_MANT_DIG */

src/s_cpowf.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* $OpenBSD: s_cpowf.c,v 1.2 2010/07/18 18:42:26 guenther 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+
/* cpowf
19+
*
20+
* Complex power function
21+
*
22+
*
23+
*
24+
* SYNOPSIS:
25+
*
26+
* float complex cpowf();
27+
* float complex a, z, w;
28+
*
29+
* w = cpowf (a, z);
30+
*
31+
*
32+
*
33+
* DESCRIPTION:
34+
*
35+
* Raises complex A to the complex Zth power.
36+
* Definition is per AMS55 # 4.2.8,
37+
* analytically equivalent to cpow(a,z) = cexp(z clog(a)).
38+
*
39+
* ACCURACY:
40+
*
41+
* Relative error:
42+
* arithmetic domain # trials peak rms
43+
* IEEE -10,+10 30000 9.4e-15 1.5e-15
44+
*
45+
*/
46+
47+
#include <complex.h>
48+
#include <math.h>
49+
50+
float complex
51+
cpowf(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) {
60+
return (0.0f + 0.0f * I);
61+
}
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+
}
69+
w = r * cosf (theta) + (r * sinf (theta)) * I;
70+
return (w);
71+
}

src/s_cpowl.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* $OpenBSD: s_cpowl.c,v 1.2 2011/07/20 19:28:33 martynas Exp $ */
2+
3+
/*
4+
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
5+
*
6+
* Permission to use, copy, modify, and distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
/* cpowl
20+
*
21+
* Complex power function
22+
*
23+
*
24+
*
25+
* SYNOPSIS:
26+
*
27+
* long double complex cpowl();
28+
* long double complex a, z, w;
29+
*
30+
* w = cpowl (a, z);
31+
*
32+
*
33+
*
34+
* DESCRIPTION:
35+
*
36+
* Raises complex A to the complex Zth power.
37+
* Definition is per AMS55 # 4.2.8,
38+
* analytically equivalent to cpow(a,z) = cexp(z clog(a)).
39+
*
40+
* ACCURACY:
41+
*
42+
* Relative error:
43+
* arithmetic domain # trials peak rms
44+
* IEEE -10,+10 30000 9.4e-15 1.5e-15
45+
*
46+
*/
47+
48+
#include <complex.h>
49+
#include <math.h>
50+
51+
long double complex
52+
cpowl(long double complex a, long double complex z)
53+
{
54+
long double complex w;
55+
long double x, y, r, theta, absa, arga;
56+
57+
x = creall(z);
58+
y = cimagl(z);
59+
absa = cabsl(a);
60+
if (absa == 0.0L) {
61+
return (0.0L + 0.0L * I);
62+
}
63+
arga = cargl(a);
64+
r = powl(absa, x);
65+
theta = x * arga;
66+
if (y != 0.0L) {
67+
r = r * expl(-y * arga);
68+
theta = theta + y * logl(absa);
69+
}
70+
w = r * cosl(theta) + (r * sinl(theta)) * I;
71+
return (w);
72+
}

0 commit comments

Comments
 (0)