From: John Marino Date: Sun, 30 Nov 2014 21:23:15 +0000 (+0100) Subject: libm: bring in 16 complex functions from NetBSD X-Git-Tag: v4.2.0rc~1343 X-Git-Url: https://gitweb.dragonflybsd.org/~tuxillo/dragonfly.git/commitdiff_plain/51a20a6e36a735a8fdc39066a0e405c51e4fc539 libm: bring in 16 complex functions from NetBSD FreeBSD is still missing a number of (obscure) complex functions that causes GCC conclude that C99 is not supported. Seven weeks ago, NetBSD brought the functions into their base. To avoid a repeat of the unholy mixture of libm from FreeBSD and NetBSD that we had before, I've created a separate directory for NetBSD functions called "gaps". If/when FreeBSD acquires these functions, we can remove files from "gaps" as we sync their equivalents. The NetBSD sources were modified as follows: * On the man pages, references to the float and double versions of the functions were removed when only the long double version was imported. This includes singular/plural changes, and file/function name changes. * Changed "#include " to "#include "math.h" * Removed the include for namespace.h * Removed all "#if 0" blocks The sixteen functions have symbol versions of DF402.0 and are: * cpow cpowf cpowl * clog clogf clogl * cacosl casinl catanl * ccoshl csinhl ctanhl * ccosl csinl ctanl * cexpl --- diff --git a/lib/libm/Makefile b/lib/libm/Makefile index 3b25ca7dda..be5ac610e1 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -22,6 +22,7 @@ CFLAGS+= -I${.CURDIR}/ld80 .PATH: ${.CURDIR}/bsdsrc .PATH: ${.CURDIR}/src .PATH: ${.CURDIR}/man +.PATH: ${.CURDIR}/gaps LIB= m SHLIB_MAJOR= 4 @@ -91,6 +92,12 @@ COMMON_SRCS+= catrig.c catrigf.c \ s_cproj.c s_cprojf.c s_creal.c s_crealf.c s_creall.c \ s_csinh.c s_csinhf.c s_ctanh.c s_ctanhf.c +# C99 complex functions from NetBSD +COMMON_SRCS+= cacosl.c casinl.c catanl.c ccoshl.c ccosl.c \ + csinl.c csinhl.c ctanl.c ctanhl.c cexpl.c \ + clog.c clogf.c clogl.c cpow.c cpowf.c cpowl.c \ + cephes_subrl.c + # libc supplies these functions: #COMMON_SRCS+= s_fabs.c s_frexp.c s_isnan.c s_ldexp.c s_modf.c @@ -308,4 +315,13 @@ MLINKS+=tanh.3 tanhf.3 \ MLINKS+=trunc.3 truncf.3 \ trunc.3 truncl.3 + +# C99 complex functions man pages from NetBSD +MAN+= cacosl.3 casinl.3 catanl.3 ccoshl.3 ccosl.3 \ + csinl.3 csinhl.3 ctanl.3 ctanhl.3 cexpl.3 clog.3 cpow.3 +MLINKS+=clog.3 clogf.3 \ + clog.3 clogl.3 +MLINKS+=cpow.3 cpowf.3 \ + cpow.3 cpowl.3 + .include diff --git a/lib/libm/Symbol.map b/lib/libm/Symbol.map index 58b312c8df..2c8eecdb36 100644 --- a/lib/libm/Symbol.map +++ b/lib/libm/Symbol.map @@ -282,7 +282,23 @@ DF306.1 { */ DF402.0 { + cacosl; + casinl; + catanl; + ccoshl; + ccosl; coshl; + csinl; + csinhl; + ctanl; + ctanhl; + cexpl; + clog; + clogf; + clogl; + cpow; + cpowf; + cpowl; erfcl; erfl; lgammal; diff --git a/lib/libm/gaps/cacosl.3 b/lib/libm/gaps/cacosl.3 new file mode 100644 index 0000000000..f2b5b74f6e --- /dev/null +++ b/lib/libm/gaps/cacosl.3 @@ -0,0 +1,39 @@ +.\" $NetBSD: cacos.3,v 1.3 2013/01/29 02:05:08 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CACOSL 3 +.Os +.Sh NAME +.Nm cacosl +.Nd complex arc cosine function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn cacosl "long double complex z" +.Sh DESCRIPTION +This function computes the complex arc cosine of +.Ar z , +with branch cuts outside the interval [\-1,\ +1] along the +real axis. +.Sh RETURN VALUES +This function returns the complex arc cosine value, in the +range of a strip mathematically unbounded along the imaginary +axis and in the interval [0,\ pi] along the real axis. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr ccos 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/cacosl.c b/lib/libm/gaps/cacosl.c new file mode 100644 index 0000000000..52699ddcba --- /dev/null +++ b/lib/libm/gaps/cacosl.c @@ -0,0 +1,44 @@ +/* $NetBSD: cacosl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" +#include "cephes_subrl.h" + +long double complex +cacosl(long double complex z) +{ + long double complex w; + + w = casinl(z); + w = (M_PI_2L - creall(w)) - cimagl(w) * I; + return w; +} diff --git a/lib/libm/gaps/casinl.3 b/lib/libm/gaps/casinl.3 new file mode 100644 index 0000000000..c7ce1a4c2e --- /dev/null +++ b/lib/libm/gaps/casinl.3 @@ -0,0 +1,40 @@ +.\" $NetBSD: casin.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CASINL 3 +.Os +.Sh NAME +.Nm casinl +.Nd complex arc sine function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn casinl "long double complex z" +.Sh DESCRIPTION +This function computes the complex arc sine of +.Ar z , +with branch cuts outside the interval [\-1,\ +1] along the +real axis. +.Sh RETURN VALUES +This function returns the complex arc sine value, in the range +of a strip mathematically unbounded along the imaginary +axis and in the interval [\-pi/2,\ +pi/2] along the +real axis. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr csin 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/casinl.c b/lib/libm/gaps/casinl.c new file mode 100644 index 0000000000..9a8d5cc8c2 --- /dev/null +++ b/lib/libm/gaps/casinl.c @@ -0,0 +1,61 @@ +/* $NetBSD: casinl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" + +long double complex +casinl(long double complex z) +{ + long double complex w; + long double complex ca, ct, zz, z2; + long double x, y; + + x = creall(z); + y = cimagl(z); + + + ca = x + y * I; + ct = ca * I; + /* sqrtl( 1 - z*z) */ + /* cmull( &ca, &ca, &zz ) */ + /*x * x - y * y */ + zz = (x - y) * (x + y) + (2.0L * x * y) * I; + + zz = 1.0L - creall(zz) - cimagl(zz) * I; + z2 = csqrtl(zz); + + zz = ct + z2; + zz = clogl(zz); + /* multiply by 1/i = -i */ + w = zz * (-1.0L * I); + return w; +} diff --git a/lib/libm/gaps/catanl.3 b/lib/libm/gaps/catanl.3 new file mode 100644 index 0000000000..246850f81f --- /dev/null +++ b/lib/libm/gaps/catanl.3 @@ -0,0 +1,40 @@ +.\" $NetBSD: catan.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CATANL 3 +.Os +.Sh NAME +.Nm catanl +.Nd complex arc tangent function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn catanl "long double complex z" +.Sh DESCRIPTION +This function computes the complex arc tangent of +.Ar z , +with branch cuts outside the interval +[\- i,\ +i] along the imaginary axis. +.Sh RETURN VALUES +This function returns the complex arc tangent value, in the +range of a strip mathematically unbounded along the imaginary +axis and in the interval [-pi/2,\ +pi/2] along the +real axis. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr ctan 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/catanl.c b/lib/libm/gaps/catanl.c new file mode 100644 index 0000000000..c69f8f23f5 --- /dev/null +++ b/lib/libm/gaps/catanl.c @@ -0,0 +1,72 @@ +/* $NetBSD: catanl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "math.h" +#include "cephes_subrl.h" + +#define MAXNUM LDBL_MAX + +long double complex +catanl(long double complex z) +{ + long double complex w; + long double a, t, x, x2, y; + + x = creall(z); + y = cimagl(z); + + if ((x == 0.0L) && (y > 1.0L)) + goto ovrf; + + x2 = x * x; + a = 1.0L - x2 - (y * y); + if (a == 0.0) + goto ovrf; + + t = 0.5L * atan2l(2.0L * x, a); + w = _redupil(t); + + t = y - 1.0L; + a = x2 + (t * t); + if (a == 0.0L) + goto ovrf; + + t = y + 1.0L; + a = (x2 + (t * t))/a; + w = w + (0.25L * logl(a)) * I; + return w; + +ovrf: + w = MAXNUM + MAXNUM * I; + return w; +} diff --git a/lib/libm/gaps/ccoshl.3 b/lib/libm/gaps/ccoshl.3 new file mode 100644 index 0000000000..5713177bb3 --- /dev/null +++ b/lib/libm/gaps/ccoshl.3 @@ -0,0 +1,35 @@ +.\" $NetBSD: ccosh.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CCOSHL 3 +.Os +.Sh NAME +.Nm ccoshl +.Nd complex hyperbolic cosine function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn ccoshl "long double complex z" +.Sh DESCRIPTION +This function computes the complex hyperbolic cosine of +.Ar z . +.Sh RETURN VALUES +This function returns the complex hyperbolic cosine value. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr cacosh 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/ccoshl.c b/lib/libm/gaps/ccoshl.c new file mode 100644 index 0000000000..aaa3a31898 --- /dev/null +++ b/lib/libm/gaps/ccoshl.c @@ -0,0 +1,45 @@ +/* $NetBSD: ccoshl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" + +long double complex +ccoshl(long double complex z) +{ + long double complex w; + long double x, y; + + x = creall(z); + y = cimagl(z); + w = coshl(x) * cosl(y) + (sinhl(x) * sinl(y)) * I; + return w; +} diff --git a/lib/libm/gaps/ccosl.3 b/lib/libm/gaps/ccosl.3 new file mode 100644 index 0000000000..cc3f058ee7 --- /dev/null +++ b/lib/libm/gaps/ccosl.3 @@ -0,0 +1,35 @@ +.\" $NetBSD: ccos.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CCOSL 3 +.Os +.Sh NAME +.Nm ccosl +.Nd complex cosine function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn ccosl "long double complex z" +.Sh DESCRIPTION +This function computes the complex cosine of +.Ar z . +.Sh RETURN VALUES +This function returns the complex cosine value. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr cacos 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/ccosl.c b/lib/libm/gaps/ccosl.c new file mode 100644 index 0000000000..e14a8fc464 --- /dev/null +++ b/lib/libm/gaps/ccosl.c @@ -0,0 +1,45 @@ +/* $NetBSD: ccosl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" +#include "cephes_subrl.h" + +long double complex +ccosl(long double complex z) +{ + long double complex w; + long double ch, sh; + + _cchshl(cimagl(z), &ch, &sh); + w = cosl(creall(z)) * ch - (sinl(creall(z)) * sh) * I; + return w; +} diff --git a/lib/libm/gaps/cephes_subrl.c b/lib/libm/gaps/cephes_subrl.c new file mode 100644 index 0000000000..3bf76f0b30 --- /dev/null +++ b/lib/libm/gaps/cephes_subrl.c @@ -0,0 +1,128 @@ +/* $NetBSD: cephes_subrl.c,v 1.2 2014/10/10 14:06:40 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" +#include "cephes_subrl.h" + +/* calculate cosh and sinh */ + +void +_cchshl(long double x, long double *c, long double *s) +{ + long double e, ei; + + if (fabsl(x) <= 0.5L) { + *c = coshl(x); + *s = sinhl(x); + } else { + e = expl(x); + ei = 0.5L / e; + e = 0.5L * e; + *s = e - ei; + *c = e + ei; + } +} + +/* Program to subtract nearest integer multiple of PI */ + +/* extended precision value of PI: */ +static const long double DP1 = 3.14159265358979323829596852490908531763125L; +static const long double DP2 = 1.6667485837041756656403424829301998703007e-19L; +#ifndef __vax__ +static const long double DP3 = 1.8830410776607851167459095484560349402753e-39L; +#define MACHEPL 1.1e-38L +#else +static const long double DP3 = 0L; +#define MACHEPL 1.1e-19L +#endif + +long double +_redupil(long double x) +{ + long double t; + long long i; + + t = x / M_PIL; + if (t >= 0.0L) + t += 0.5L; + else + t -= 0.5L; + + i = t; /* the multiple */ + t = i; + t = ((x - t * DP1) - t * DP2) - t * DP3; + return t; +} + +/* Taylor series expansion for cosh(2y) - cos(2x) */ + +long double +_ctansl(long double complex z) +{ + long double f, x, x2, y, y2, rn, t; + long double d; + + x = fabsl(2.0L * creall(z)); + y = fabsl(2.0L * cimagl(z)); + + x = _redupil(x); + + x = x * x; + y = y * y; + x2 = 1.0; + y2 = 1.0; + f = 1.0; + rn = 0.0; + d = 0.0; + do { + rn += 1.0L; + f *= rn; + rn += 1.0L; + f *= rn; + x2 *= x; + y2 *= y; + t = y2 + x2; + t /= f; + d += t; + + rn += 1.0L; + f *= rn; + rn += 1.0L; + f *= rn; + x2 *= x; + y2 *= y; + t = y2 - x2; + t /= f; + d += t; + } while (fabsl(t/d) > MACHEPL); + return d; +} diff --git a/lib/libm/gaps/cephes_subrl.h b/lib/libm/gaps/cephes_subrl.h new file mode 100644 index 0000000000..6354b23a75 --- /dev/null +++ b/lib/libm/gaps/cephes_subrl.h @@ -0,0 +1,9 @@ +/* $NetBSD: cephes_subrl.h,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +void _cchshl(long double, long double *, long double *); +long double _redupil(long double); +long double _ctansl(long double complex); + +#define M_PIL 3.14159265358979323846264338327950280e+00L +#define M_PI_2L 1.57079632679489661923132169163975140e+00L + diff --git a/lib/libm/gaps/cexpl.3 b/lib/libm/gaps/cexpl.3 new file mode 100644 index 0000000000..c03a856425 --- /dev/null +++ b/lib/libm/gaps/cexpl.3 @@ -0,0 +1,37 @@ +.\" $NetBSD: cexp.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CEXPL 3 +.Os +.Sh NAME +.Nm cexpl +.Nd complex exponential function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn cexpl "long double complex z" +.Sh DESCRIPTION +This function computes the complex exponent of +.Ar z , +defined as e**z. +.Sh RETURN VALUES +This function returns the complex exponential value of +.Ar z . +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr clog 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/cexpl.c b/lib/libm/gaps/cexpl.c new file mode 100644 index 0000000000..9e6cc208b2 --- /dev/null +++ b/lib/libm/gaps/cexpl.c @@ -0,0 +1,46 @@ +/* $NetBSD: cexpl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" + +long double complex +cexpl(long double complex z) +{ + long double complex w; + long double r, x, y; + + x = creall(z); + y = cimagl(z); + r = expl(x); + w = r * cosl(y) + r * sinl(y) * I; + return w; +} diff --git a/lib/libm/gaps/clog.3 b/lib/libm/gaps/clog.3 new file mode 100644 index 0000000000..0839b8e36f --- /dev/null +++ b/lib/libm/gaps/clog.3 @@ -0,0 +1,46 @@ +.\" $NetBSD: clog.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CLOG 3 +.Os +.Sh NAME +.Nm clog , +.Nm clogf , +.Nm clogl +.Nd complex natural logarithm functions +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn clog "double complex z" +.Ft float complex +.Fn clogf "float complex z" +.Ft long double complex +.Fn clogl "long double complex z" +.Sh DESCRIPTION +These functions compute the complex natural (base e) logarithm +of +.Ar z , +with a branch cut along the negative real axis. +.Sh RETURN VALUES +These functions return the complex natural logarithm value, +in the range of a strip mathematically unbounded along the +real axis and in the interval [\-i pi,\ +i pi] along the +imaginary axis. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr cexp 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/clog.c b/lib/libm/gaps/clog.c new file mode 100644 index 0000000000..a667f4f930 --- /dev/null +++ b/lib/libm/gaps/clog.c @@ -0,0 +1,46 @@ +/* $NetBSD: clog.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" + +double complex +clog(double complex z) +{ + double complex w; + double p, rr; + + rr = cabs(z); + p = log(rr); + rr = atan2(cimag(z), creal(z)); + w = p + rr * I; + return w; +} diff --git a/lib/libm/gaps/clogf.c b/lib/libm/gaps/clogf.c new file mode 100644 index 0000000000..5cd7611a2c --- /dev/null +++ b/lib/libm/gaps/clogf.c @@ -0,0 +1,46 @@ +/* $NetBSD: clogf.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" + +float complex +clogf(float complex z) +{ + float complex w; + float p, rr; + + rr = cabsf(z); + p = logf(rr); + rr = atan2f(cimagf(z), crealf(z)); + w = p + rr * I; + return w; +} diff --git a/lib/libm/gaps/clogl.c b/lib/libm/gaps/clogl.c new file mode 100644 index 0000000000..b89d782c31 --- /dev/null +++ b/lib/libm/gaps/clogl.c @@ -0,0 +1,46 @@ +/* $NetBSD: clogl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" + +long double complex +clogl(long double complex z) +{ + long double complex w; + long double p, rr; + + rr = cabsl(z); + p = logl(rr); + rr = atan2l(cimagl(z), creall(z)); + w = p + rr * I; + return w; +} diff --git a/lib/libm/gaps/cpow.3 b/lib/libm/gaps/cpow.3 new file mode 100644 index 0000000000..95c9dbeca4 --- /dev/null +++ b/lib/libm/gaps/cpow.3 @@ -0,0 +1,43 @@ +.\" $NetBSD: cpow.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CPOW 3 +.Os +.Sh NAME +.Nm cpow , +.Nm cpowf , +.Nm cpowl +.Nd complex power functions +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn cpow "double complex x" "double complex y" +.Ft float complex +.Fn cpowf "float complex x" "float complex y" +.Ft long double complex +.Fn cpowl "long double complex x" "long double complex y" +.Sh DESCRIPTION +These functions compute the complex power function x**y, +with a branch cut for the first +parameter along the negative real axis. +.Sh RETURN VALUES +These functions return the complex power function value. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr cabs 3 , +.Xr csqrt 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/cpow.c b/lib/libm/gaps/cpow.c new file mode 100644 index 0000000000..90c72296ac --- /dev/null +++ b/lib/libm/gaps/cpow.c @@ -0,0 +1,56 @@ +/* $NetBSD: cpow.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#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; +} diff --git a/lib/libm/gaps/cpowf.c b/lib/libm/gaps/cpowf.c new file mode 100644 index 0000000000..48436fed24 --- /dev/null +++ b/lib/libm/gaps/cpowf.c @@ -0,0 +1,56 @@ +/* $NetBSD: cpowf.c,v 1.1 2007/08/20 16:01:36 drochner Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#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; +} diff --git a/lib/libm/gaps/cpowl.c b/lib/libm/gaps/cpowl.c new file mode 100644 index 0000000000..9c9b47535a --- /dev/null +++ b/lib/libm/gaps/cpowl.c @@ -0,0 +1,56 @@ +/* $NetBSD: cpowl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#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; +} diff --git a/lib/libm/gaps/csinhl.3 b/lib/libm/gaps/csinhl.3 new file mode 100644 index 0000000000..0ce93ad629 --- /dev/null +++ b/lib/libm/gaps/csinhl.3 @@ -0,0 +1,35 @@ +.\" $NetBSD: csinh.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CSINHL 3 +.Os +.Sh NAME +.Nm csinhl +.Nd complex hyperbolic sine function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn csinhl "long double complex z" +.Sh DESCRIPTION +This function computes the complex hyperbolic sine of +.Ar z . +.Sh RETURN VALUES +This function returns the complex hyperbolic sine value. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr casinh 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/csinhl.c b/lib/libm/gaps/csinhl.c new file mode 100644 index 0000000000..f9fb126340 --- /dev/null +++ b/lib/libm/gaps/csinhl.c @@ -0,0 +1,45 @@ +/* $NetBSD: csinhl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" + +long double complex +csinhl(long double complex z) +{ + long double complex w; + long double x, y; + + x = creall(z); + y = cimagl(z); + w = sinhl(x) * cosl(y) + (coshl(x) * sinl(y)) * I; + return w; +} diff --git a/lib/libm/gaps/csinl.3 b/lib/libm/gaps/csinl.3 new file mode 100644 index 0000000000..84669db269 --- /dev/null +++ b/lib/libm/gaps/csinl.3 @@ -0,0 +1,35 @@ +.\" $NetBSD: csin.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CSINL 3 +.Os +.Sh NAME +.Nm csinl +.Nd complex sine function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn csinl "long double complex z" +.Sh DESCRIPTION +This function computes the complex sine of +.Ar z . +.Sh RETURN VALUES +This function returns the complex sine value. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr casin 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/csinl.c b/lib/libm/gaps/csinl.c new file mode 100644 index 0000000000..aabc12cdf5 --- /dev/null +++ b/lib/libm/gaps/csinl.c @@ -0,0 +1,45 @@ +/* $NetBSD: csinl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" +#include "cephes_subrl.h" + +long double complex +csinl(long double complex z) +{ + long double complex w; + long double ch, sh; + + _cchshl(cimagl(z), &ch, &sh); + w = sinl(creall(z)) * ch + (cosl(creall(z)) * sh) * I; + return w; +} diff --git a/lib/libm/gaps/ctanhl.3 b/lib/libm/gaps/ctanhl.3 new file mode 100644 index 0000000000..dc06382138 --- /dev/null +++ b/lib/libm/gaps/ctanhl.3 @@ -0,0 +1,35 @@ +.\" $NetBSD: ctanh.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CTANHL 3 +.Os +.Sh NAME +.Nm ctanhl +.Nd complex hyperbolic tangent function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn ctanhl "long double complex z" +.Sh DESCRIPTION +This function computes the complex hyperbolic tangent of +.Ar z . +.Sh RETURN VALUES +This function returns the complex hyperbolic tangent value. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr catanh 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/ctanhl.c b/lib/libm/gaps/ctanhl.c new file mode 100644 index 0000000000..1086582220 --- /dev/null +++ b/lib/libm/gaps/ctanhl.c @@ -0,0 +1,47 @@ +/* $NetBSD: ctanhl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "math.h" + +long double complex +ctanhl(long double complex z) +{ + long double complex w; + long double x, y, d; + + x = creall(z); + y = cimagl(z); + d = coshl(2.0L * x) + cosl(2.0L * y); + w = sinhl(2.0L * x) / d + (sinl(2.0L * y) / d) * I; + + return w; +} diff --git a/lib/libm/gaps/ctanl.3 b/lib/libm/gaps/ctanl.3 new file mode 100644 index 0000000000..4ab9429166 --- /dev/null +++ b/lib/libm/gaps/ctanl.3 @@ -0,0 +1,35 @@ +.\" $NetBSD: ctan.3,v 1.3 2013/01/29 02:05:09 matt Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.Dd November 30, 2014 +.Dt CTANL 3 +.Os +.Sh NAME +.Nm ctanl +.Nd complex tangent function +.Sh SYNOPSIS +.In complex.h +.Ft long double complex +.Fn ctanl "long double complex z" +.Sh DESCRIPTION +This function computes the complex tangent of +.Ar z . +.Sh RETURN VALUES +This function returns the complex tangent value. +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr catan 3 , +.St -p1003.1-2001 +.Aq Pa complex.h +.Sh COPYRIGHT +Portions of this text are reprinted and reproduced in electronic form +from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology +-- Portable Operating System Interface (POSIX), The Open Group Base +Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of +Electrical and Electronics Engineers, Inc and The Open Group. +In the +event of any discrepancy between this version and the original IEEE and +The Open Group Standard, the original IEEE and The Open Group Standard +is the referee document. +The original Standard can be obtained online at +http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/gaps/ctanl.c b/lib/libm/gaps/ctanl.c new file mode 100644 index 0000000000..09e91fe3ba --- /dev/null +++ b/lib/libm/gaps/ctanl.c @@ -0,0 +1,58 @@ +/* $NetBSD: ctanl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software written by Stephen L. Moshier. + * It is redistributed by the NetBSD Foundation by permission of the author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "math.h" +#include "cephes_subrl.h" + +#define MAXNUM LDBL_MAX + +long double complex +ctanl(long double complex z) +{ + long double complex w; + long double d; + + d = cosl(2.0L * creall(z)) + coshl(2.0L * cimagl(z)); + + if (fabsl(d) < 0.25L) + d = _ctansl(z); + + if (d == 0.0L) { + /* mtherr ("ctan", OVERFLOW); */ + w = MAXNUM + MAXNUM * I; + return w; + } + + w = sinl(2.0L * creall(z)) / d + (sinhl(2.0L * cimagl(z)) / d) * I; + return w; +} diff --git a/lib/libm/src/complex.h b/lib/libm/src/complex.h index 282ba15a3f..f179b55ca8 100644 --- a/lib/libm/src/complex.h +++ b/lib/libm/src/complex.h @@ -111,6 +111,27 @@ float complex ctanf(float complex); double complex ctanh(double complex); float complex ctanhf(float complex); + +/* Remaining complex functions from NetBSD */ +long double complex cacosl(long double complex); +long double complex casinl(long double complex); +long double complex catanl(long double complex); +long double complex ccoshl(long double complex); +long double complex ccosl(long double complex); +long double complex csinl(long double complex); +long double complex csinhl(long double complex); +long double complex ctanl(long double complex); +long double complex ctanhl(long double complex); +long double complex cexpl(long double complex); +long double complex clogl(long double complex); +long double complex cpowl(long double complex, long double complex); + +double complex clog(double complex); +double complex cpow(double complex, double complex); + +float complex clogf(float complex); +float complex cpowf(float complex, float complex); + __END_DECLS #endif /* _COMPLEX_H */