Add cpow from OpenBSD

Use clang by default on Darwin
Enable cpow tests

Fix #22
This commit is contained in:
Viral B. Shah 2013-07-14 18:33:56 +05:30
parent 0cd232d8cf
commit 29af332f36
5 changed files with 226 additions and 1 deletions

View File

@ -8,6 +8,12 @@ FFLAGS += -O3
USEGCC = 1
USECLANG = 0
ifeq ($(OS), Darwin)
USEGCC = 0
USECLANG = 1
endif
AR = ar
ifeq ($(USECLANG),1)
USEGCC = 0
@ -19,7 +25,6 @@ ifeq ($(USEGCC),1)
CC = gcc
CFLAGS_add += -fno-gnu89-inline
endif
AR = ar
ARCH := $(shell $(CC) -dumpmachine | sed "s/\([^-]*\).*$$/\1/")
ifeq ($(ARCH),mingw32)

View File

@ -30,6 +30,7 @@ $(CUR_SRCS) = \
s_scalbln.c s_scalbn.c s_scalbnf.c s_signbit.c \
s_signgam.c s_significand.c s_significandf.c s_sin.c s_sinf.c \
s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_tgammaf.c s_trunc.c s_truncf.c \
s_cpow.c s_cpowf.c s_cpowl.c \
w_cabs.c w_cabsf.c w_drem.c w_dremf.c
ifneq ($(OS), WINNT)

76
src/s_cpow.c Normal file
View File

@ -0,0 +1,76 @@
/* $OpenBSD: s_cpow.c,v 1.6 2013/07/03 04:46:36 espie Exp $ */
/*
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* cpow
*
* Complex power function
*
*
*
* SYNOPSIS:
*
* double complex cpow();
* double complex a, z, w;
*
* w = cpow (a, z);
*
*
*
* DESCRIPTION:
*
* Raises complex A to the complex Zth power.
* Definition is per AMS55 # 4.2.8,
* analytically equivalent to cpow(a,z) = cexp(z clog(a)).
*
* ACCURACY:
*
* Relative error:
* arithmetic domain # trials peak rms
* IEEE -10,+10 30000 9.4e-15 1.5e-15
*
*/
#include <complex.h>
#include <float.h>
#include <math.h>
double complex
cpow(double complex a, double complex z)
{
double complex w;
double x, y, r, theta, absa, arga;
x = creal (z);
y = cimag (z);
absa = cabs (a);
if (absa == 0.0) {
return (0.0 + 0.0 * I);
}
arga = carg (a);
r = pow (absa, x);
theta = x * arga;
if (y != 0.0) {
r = r * exp (-y * arga);
theta = theta + y * log (absa);
}
w = r * cos (theta) + (r * sin (theta)) * I;
return (w);
}
#if LDBL_MANT_DIG == DBL_MANT_DIG
__strong_alias(cpowl, cpow);
#endif /* LDBL_MANT_DIG == DBL_MANT_DIG */

71
src/s_cpowf.c Normal file
View File

@ -0,0 +1,71 @@
/* $OpenBSD: s_cpowf.c,v 1.2 2010/07/18 18:42:26 guenther Exp $ */
/*
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* cpowf
*
* Complex power function
*
*
*
* SYNOPSIS:
*
* float complex cpowf();
* float complex a, z, w;
*
* w = cpowf (a, z);
*
*
*
* DESCRIPTION:
*
* Raises complex A to the complex Zth power.
* Definition is per AMS55 # 4.2.8,
* analytically equivalent to cpow(a,z) = cexp(z clog(a)).
*
* ACCURACY:
*
* Relative error:
* arithmetic domain # trials peak rms
* IEEE -10,+10 30000 9.4e-15 1.5e-15
*
*/
#include <complex.h>
#include <math.h>
float complex
cpowf(float complex a, float complex z)
{
float complex w;
float x, y, r, theta, absa, arga;
x = crealf(z);
y = cimagf(z);
absa = cabsf (a);
if (absa == 0.0f) {
return (0.0f + 0.0f * I);
}
arga = cargf (a);
r = powf (absa, x);
theta = x * arga;
if (y != 0.0f) {
r = r * expf (-y * arga);
theta = theta + y * logf (absa);
}
w = r * cosf (theta) + (r * sinf (theta)) * I;
return (w);
}

72
src/s_cpowl.c Normal file
View File

@ -0,0 +1,72 @@
/* $OpenBSD: s_cpowl.c,v 1.2 2011/07/20 19:28:33 martynas Exp $ */
/*
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* cpowl
*
* Complex power function
*
*
*
* SYNOPSIS:
*
* long double complex cpowl();
* long double complex a, z, w;
*
* w = cpowl (a, z);
*
*
*
* DESCRIPTION:
*
* Raises complex A to the complex Zth power.
* Definition is per AMS55 # 4.2.8,
* analytically equivalent to cpow(a,z) = cexp(z clog(a)).
*
* ACCURACY:
*
* Relative error:
* arithmetic domain # trials peak rms
* IEEE -10,+10 30000 9.4e-15 1.5e-15
*
*/
#include <complex.h>
#include <math.h>
long double complex
cpowl(long double complex a, long double complex z)
{
long double complex w;
long double x, y, r, theta, absa, arga;
x = creall(z);
y = cimagl(z);
absa = cabsl(a);
if (absa == 0.0L) {
return (0.0L + 0.0L * I);
}
arga = cargl(a);
r = powl(absa, x);
theta = x * arga;
if (y != 0.0L) {
r = r * expl(-y * arga);
theta = theta + y * logl(absa);
}
w = r * cosl(theta) + (r * sinl(theta)) * I;
return (w);
}