From: Stathis Kamperis Date: Sat, 18 Jul 2009 06:49:51 +0000 (+0300) Subject: Import complex arithmetic functions from {Net,Free}BSD. X-Git-Url: https://gitweb.dragonflybsd.org/~corecode/dragonfly.git/commitdiff_plain/cd2c0f90f57b10005fb2df56c61950affea82480 Import complex arithmetic functions from {Net,Free}BSD. swildner@ helped test it with llvm/clang. Dragonfly-bug: --- diff --git a/include/complex.h b/include/complex.h index f975c5ab72..d73233f555 100644 --- a/include/complex.h +++ b/include/complex.h @@ -31,10 +31,14 @@ #define _COMPLEX_H #ifdef __GNUC__ +#if __STDC_VERSION__ < 199901L #define _Complex __complex__ -#define _Complex_I 1.0fi #endif +#define _Complex_I 1.0fi +#endif /* !__GNUC__ */ +/* 7.3 Complex arithmetic */ +/* 7.3.1 */ #define complex _Complex #define I _Complex_I @@ -42,20 +46,103 @@ __BEGIN_DECLS -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); +/* 7.3.5 Trigonometric functions */ +/* 7.3.5.1 The cacos functions */ +double complex cacos(double complex); +float complex cacosf(float complex); -__END_DECLS +/* 7.3.5.2 The casin functions */ +double complex casin(double complex); +float complex casinf(float complex); -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif +/* 7.3.5.3 The catan functions */ +double complex catan(double complex); +float complex catanf(float complex); + +/* 7.3.5.4 The ccos functions */ +double complex ccos(double complex); +float complex ccosf(float complex); + +/* 7.3.5.5 The csin functions */ +double complex csin(double complex); +float complex csinf(float complex); + +/* 7.3.5.6 The ctan functions */ +double complex ctan(double complex); +float complex ctanf(float complex); + +/* 7.3.6 Hyperbolic functions */ +/* 7.3.6.1 The cacosh functions */ +double complex cacosh(double complex); +float complex cacoshf(float complex); + +/* 7.3.6.2 The casinh functions */ +double complex casinh(double complex); +float complex casinhf(float complex); + +/* 7.3.6.3 The catanh functions */ +double complex catanh(double complex); +float complex catanhf(float complex); + +/* 7.3.6.4 The ccosh functions */ +double complex ccosh(double complex); +float complex ccoshf(float complex); + +/* 7.3.6.5 The csinh functions */ +double complex csinh(double complex); +float complex csinhf(float complex); + +/* 7.3.6.6 The ctanh functions */ +double complex ctanh(double complex); +float complex ctanhf(float complex); + +/* 7.3.7 Exponential and logarithmic functions */ +/* 7.3.7.1 The cexp functions */ +double complex cexp(double complex); +float complex cexpf(float complex); + +/* 7.3.7.2 The clog functions */ +double complex clog(double complex); +float complex clogf(float complex); + +/* 7.3.8 Power and absolute-value functions */ +/* 7.3.8.1 The cabs functions */ +double cabs(double complex); +float cabsf(float complex); + +/* 7.3.8.2 The cpow functions */ +double complex cpow(double complex, double complex); +float complex cpowf(float complex, float complex); + +/* 7.3.8.3 The csqrt functions */ +double complex csqrt(double complex); +float complex csqrtf(float complex); + +/* 7.3.9 Manipulation functions */ +/* 7.3.9.1 The carg functions */ +double carg(double complex); +float cargf(float complex); + +/* 7.3.9.2 The cimag functions */ +double cimag(double complex); +float cimagf(float complex); +long double cimagl(long double complex); + +/* 7.3.9.3 The conj functions */ +double complex conj(double complex); +float complex conjf(float complex); +long double complex conjl(long double complex); + +/* 7.3.9.4 The cproj functions */ +double complex cproj(double complex); +float complex cprojf(float complex); +long double complex cprojl(long double complex); + +/* 7.3.9.5 The creal functions */ +double creal(double complex); +float crealf(float complex); +long double creall(long double complex); + +__END_DECLS #endif /* _COMPLEX_H */ diff --git a/include/math.h b/include/math.h index 637b46096b..bb6b4ac998 100644 --- a/include/math.h +++ b/include/math.h @@ -315,6 +315,8 @@ float remainderf(float, float); /* 7.12.11 manipulation */ float copysignf(float, float); +long double copysignl(long double x, long double y); + double nan(const char *); float nanf(const char *); long double nanl(const char *); diff --git a/lib/libm/Makefile b/lib/libm/Makefile index 286d6456ce..156fea4b26 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -9,4 +9,7 @@ WARNS?= 2 .include "man/Makefile.inc" .include "src/Makefile.inc" +# Complex arithmentic +.include "complex/Makefile.inc" + .include diff --git a/lib/libm/complex/Makefile.inc b/lib/libm/complex/Makefile.inc new file mode 100644 index 0000000000..d9d0ede339 --- /dev/null +++ b/lib/libm/complex/Makefile.inc @@ -0,0 +1,25 @@ +# $NetBSD: Makefile.inc,v 1.2 2008/03/08 14:21:41 drochner Exp $ + +.PATH: ${.CURDIR}/complex + +SRCS+= cabs.c cabsf.c carg.c cargf.c +SRCS+= creal.c crealf.c creall.c cimag.c cimagf.c cimagl.c conj.c conjf.c +SRCS+= cproj.c cprojf.c cprojl.c +SRCS+= csqrt.c cexp.c clog.c cpow.c +SRCS+= cephes_subr.c csin.c ccos.c ctan.c csinh.c ccosh.c ctanh.c +SRCS+= casin.c cacos.c catan.c casinh.c cacosh.c catanh.c +SRCS+= csqrtf.c cexpf.c clogf.c cpowf.c +SRCS+= cephes_subrf.c csinf.c ccosf.c ctanf.c csinhf.c ccoshf.c ctanhf.c +SRCS+= casinf.c cacosf.c catanf.c casinhf.c cacoshf.c catanhf.c + +MAN+= cabs.3 cacos.3 cacosh.3 carg.3 casin.3 casinh.3 catan.3 catanh.3 +MAN+= ccos.3 ccosh.3 cexp.3 cimag.3 clog.3 conj.3 cpow.3 creal.3 +MAN+= csin.3 csinh.3 csqrt.3 ctan.3 ctanh.3 + +MLINKS+= cabs.3 cabsf.3 cacos.3 cacosf.3 cacosh.3 cacoshf.3 +MLINKS+= carg.3 cargf.3 casin.3 casinf.3 casinh.3 casinhf.3 +MLINKS+= catan.3 catanf.3 catanh.3 catanhf.3 ccos.3 ccosf.3 +MLINKS+= ccosh.3 ccoshf.3 cexp.3 cexpf.3 cimag.3 cimagf.3 cimag.3 cimagl.3 +MLINKS+= clog.3 clogf.3 conj.3 conjf.3 conj.3 conjl.3 cpow.3 cpowf.3 +MLINKS+= creal.3 crealf.3 creal.3 creall.3 csin.3 csinf.3 csinh.3 csinhf.3 +MLINKS+= csqrt.3 csqrtf.3 ctan.3 ctanf.3 ctanh.3 ctanhf.3 diff --git a/lib/libm/complex/cabs.3 b/lib/libm/complex/cabs.3 new file mode 100644 index 0000000000..9ee409093e --- /dev/null +++ b/lib/libm/complex/cabs.3 @@ -0,0 +1,53 @@ +.\" $NetBSD: cabs.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CABS" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" cabs +.SH NAME +cabs, cabsf \- return a complex absolute value +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double cabs(double complex\fP \fIz\fP\fB); +.br +float cabsf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex absolute value (also called +norm, modulus, or magnitude) of \fIz\fP. +.SH RETURN VALUE +.LP +These functions return the complex absolute value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +The Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP +.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/complex/cabs.c b/lib/libm/complex/cabs.c new file mode 100644 index 0000000000..b8c8ab637c --- /dev/null +++ b/lib/libm/complex/cabs.c @@ -0,0 +1,17 @@ +/* $NetBSD: cabs.c,v 1.1 2007/08/20 16:01:30 drochner Exp $ */ + +/* + * Written by Matthias Drochner . + * Public domain. + */ + +#include +#include +#include "../src/math_private.h" + +double +cabs(double complex z) +{ + + return hypot(creal(z), cimag(z)); +} diff --git a/lib/libm/complex/cabsf.c b/lib/libm/complex/cabsf.c new file mode 100644 index 0000000000..0baf5285da --- /dev/null +++ b/lib/libm/complex/cabsf.c @@ -0,0 +1,17 @@ +/* $NetBSD: cabsf.c,v 1.1 2007/08/20 16:01:30 drochner Exp $ */ + +/* + * Written by Matthias Drochner . + * Public domain. + */ + +#include +#include +#include "../src/math_private.h" + +float +cabsf(float complex z) +{ + + return hypotf(crealf(z), cimagf(z)); +} diff --git a/lib/libm/complex/cacos.3 b/lib/libm/complex/cacos.3 new file mode 100644 index 0000000000..2e6fb5a2e4 --- /dev/null +++ b/lib/libm/complex/cacos.3 @@ -0,0 +1,57 @@ +.\" $NetBSD: cacos.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CACOS" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" cacos +.SH NAME +cacos, cacosf \- complex arc cosine functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex cacos(double complex\fP \fIz\fP\fB); +.br +float complex cacosf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex arc cosine of \fIz\fP, with +branch cuts outside the interval [-1,\ +1] along the +real axis. +.SH RETURN VALUE +.LP +These functions return 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 +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIccos\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/cacos.c b/lib/libm/complex/cacos.c new file mode 100644 index 0000000000..328a18d1ee --- /dev/null +++ b/lib/libm/complex/cacos.c @@ -0,0 +1,44 @@ +/* $NetBSD: cacos.c,v 1.1 2007/08/20 16:01:30 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 + +double complex +cacos(double complex z) +{ + double complex w; + + w = casin(z); + w = (M_PI_2 - creal(w)) - cimag(w) * I; + return w; +} diff --git a/lib/libm/complex/cacosf.c b/lib/libm/complex/cacosf.c new file mode 100644 index 0000000000..8411e58ff5 --- /dev/null +++ b/lib/libm/complex/cacosf.c @@ -0,0 +1,44 @@ +/* $NetBSD: cacosf.c,v 1.1 2007/08/20 16:01:30 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 + +float complex +cacosf(float complex z) +{ + float complex w; + + w = casinf(z); + w = ((float)M_PI_2 - crealf(w)) - cimagf(w) * I; + return w; +} diff --git a/lib/libm/complex/cacosh.3 b/lib/libm/complex/cacosh.3 new file mode 100644 index 0000000000..422e45a672 --- /dev/null +++ b/lib/libm/complex/cacosh.3 @@ -0,0 +1,58 @@ +.\" $NetBSD: cacosh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CACOSH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" cacosh +.SH NAME +cacosh, cacoshf \- complex arc hyperbolic cosine functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex cacosh(double complex\fP \fIz\fP\fB); +.br +float complex cacoshf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex arc hyperbolic cosine of +\fIz\fP, with a branch cut at values less than 1 along the +real axis. +.SH RETURN VALUE +.LP +These functions return the complex arc hyperbolic cosine value, +in the range of a half-strip of non-negative values along +the real axis and in the interval [-\fIi\fPpi,\ +\fIi\fPpi] along +the imaginary axis. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIccosh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/cacosh.c b/lib/libm/complex/cacosh.c new file mode 100644 index 0000000000..96373ae7d3 --- /dev/null +++ b/lib/libm/complex/cacosh.c @@ -0,0 +1,41 @@ +/* $NetBSD: cacosh.c,v 1.1 2007/08/20 16:01:30 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 + +double complex +cacosh(double complex z) +{ + double complex w; + + w = I * cacos(z); + return w; +} diff --git a/lib/libm/complex/cacoshf.c b/lib/libm/complex/cacoshf.c new file mode 100644 index 0000000000..ec60445aca --- /dev/null +++ b/lib/libm/complex/cacoshf.c @@ -0,0 +1,41 @@ +/* $NetBSD: cacoshf.c,v 1.1 2007/08/20 16:01:31 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 + +float complex +cacoshf(float complex z) +{ + float complex w; + + w = I * cacosf(z); + return w; +} diff --git a/lib/libm/complex/carg.3 b/lib/libm/complex/carg.3 new file mode 100644 index 0000000000..f60bbb1d15 --- /dev/null +++ b/lib/libm/complex/carg.3 @@ -0,0 +1,56 @@ +.\" $NetBSD: carg.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CARG" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" carg +.SH NAME +carg, cargf \- complex argument functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double carg(double complex\fP \fIz\fP\fB); +.br +float cargf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the argument (also called phase angle) +of \fIz\fP, with a branch cut along the negative real +axis. +.SH RETURN VALUE +.LP +These functions return the value of the argument in the interval +[-pi,\ +pi]. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcimag\fP(), \fIconj\fP(), \fIcproj\fP(), the +Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP +.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/complex/carg.c b/lib/libm/complex/carg.c new file mode 100644 index 0000000000..28fe999b55 --- /dev/null +++ b/lib/libm/complex/carg.c @@ -0,0 +1,17 @@ +/* $NetBSD: carg.c,v 1.1 2007/08/20 16:01:31 drochner Exp $ */ + +/* + * Written by Matthias Drochner . + * Public domain. + */ + + +#include +#include + +double +carg(double complex z) +{ + + return atan2(cimag(z), creal(z)); +} diff --git a/lib/libm/complex/cargf.c b/lib/libm/complex/cargf.c new file mode 100644 index 0000000000..4ed8210625 --- /dev/null +++ b/lib/libm/complex/cargf.c @@ -0,0 +1,17 @@ +/* $NetBSD: cargf.c,v 1.1 2007/08/20 16:01:31 drochner Exp $ */ + +/* + * Written by Matthias Drochner . + * Public domain. + */ + + +#include +#include + +float +cargf(float complex z) +{ + + return atan2f(cimag(z), creal(z)); +} diff --git a/lib/libm/complex/casin.3 b/lib/libm/complex/casin.3 new file mode 100644 index 0000000000..66319e3264 --- /dev/null +++ b/lib/libm/complex/casin.3 @@ -0,0 +1,58 @@ +.\" $NetBSD: casin.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CASIN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" casin +.SH NAME +casin, casinf \- complex arc sine functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex casin(double complex\fP \fIz\fP\fB); +.br +float complex casinf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex arc sine of \fIz\fP, with +branch cuts outside the interval [-1,\ +1] along the +real axis. +.SH RETURN VALUE +.LP +These functions return 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 +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcsin\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/casin.c b/lib/libm/complex/casin.c new file mode 100644 index 0000000000..92010b99eb --- /dev/null +++ b/lib/libm/complex/casin.c @@ -0,0 +1,120 @@ +/* $NetBSD: casin.c,v 1.1 2007/08/20 16:01:31 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 + +#ifdef __weak_alias +__weak_alias(casin, _casin) +#endif + +double complex +casin(double complex z) +{ + double complex w; + double complex ca, ct, zz, z2; + double x, y; + + x = creal(z); + y = cimag(z); + +#if 0 /* MD: test is incorrect, casin(>1) is defined */ + if (y == 0.0) { + if (fabs(x) > 1.0) { + w = M_PI_2 + 0.0 * I; +#if 0 + mtherr ("casin", DOMAIN); +#endif + } else { + w = asin(x) + 0.0 * I; + } + return w; + } +#endif + +/* Power series expansion */ +/* +b = cabs(z); +if( b < 0.125 ) +{ +z2.r = (x - y) * (x + y); +z2.i = 2.0 * x * y; + +cn = 1.0; +n = 1.0; +ca.r = x; +ca.i = y; +sum.r = x; +sum.i = y; +do + { + ct.r = z2.r * ca.r - z2.i * ca.i; + ct.i = z2.r * ca.i + z2.i * ca.r; + ca.r = ct.r; + ca.i = ct.i; + + cn *= n; + n += 1.0; + cn /= n; + n += 1.0; + b = cn/n; + + ct.r *= b; + ct.i *= b; + sum.r += ct.r; + sum.i += ct.i; + b = fabs(ct.r) + fabs(ct.i); + } +while( b > MACHEP ); +w->r = sum.r; +w->i = sum.i; +return; +} +*/ + + + ca = x + y * I; + ct = ca * I; + /* sqrt( 1 - z*z) */ + /* cmul( &ca, &ca, &zz ) */ + /*x * x - y * y */ + zz = (x - y) * (x + y) + (2.0 * x * y) * I; + + zz = 1.0 - creal(zz) - cimag(zz) * I; + z2 = csqrt(zz); + + zz = ct + z2; + zz = clog(zz); + /* multiply by 1/i = -i */ + w = zz * (-1.0 * I); + return w; +} diff --git a/lib/libm/complex/casinf.c b/lib/libm/complex/casinf.c new file mode 100644 index 0000000000..f123199eca --- /dev/null +++ b/lib/libm/complex/casinf.c @@ -0,0 +1,120 @@ +/* $NetBSD: casinf.c,v 1.1 2007/08/20 16:01:31 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 + +#ifdef __weak_alias +__weak_alias(casinf, _casinf) +#endif + +float complex +casinf(float complex z) +{ + float complex w; + float complex ca, ct, zz, z2; + float x, y; + + x = crealf(z); + y = cimagf(z); + +#if 0 /* MD: test is incorrect, casin(>1) is defined */ + if (y == 0.0f) { + if (fabsf(x) > 1.0) { + w = M_PI_2 + 0.0f * I; +#if 0 + mtherr ("casin", DOMAIN); +#endif + } else { + w = asinf(x) + 0.0f * I; + } + return w; + } +#endif + +/* Power series expansion */ +/* +b = cabsf(z); +if( b < 0.125 ) +{ +z2.r = (x - y) * (x + y); +z2.i = 2.0 * x * y; + +cn = 1.0; +n = 1.0; +ca.r = x; +ca.i = y; +sum.r = x; +sum.i = y; +do + { + ct.r = z2.r * ca.r - z2.i * ca.i; + ct.i = z2.r * ca.i + z2.i * ca.r; + ca.r = ct.r; + ca.i = ct.i; + + cn *= n; + n += 1.0; + cn /= n; + n += 1.0; + b = cn/n; + + ct.r *= b; + ct.i *= b; + sum.r += ct.r; + sum.i += ct.i; + b = fabsf(ct.r) + fabsf(ct.i); + } +while( b > MACHEP ); +w->r = sum.r; +w->i = sum.i; +return; +} +*/ + + + ca = x + y * I; + ct = ca * I; + /* sqrt( 1 - z*z) */ + /* cmul( &ca, &ca, &zz ) */ + /*x * x - y * y */ + zz = (x - y) * (x + y) + (2.0f * x * y) * I; + + zz = 1.0f - crealf(zz) - cimagf(zz) * I; + z2 = csqrtf(zz); + + zz = ct + z2; + zz = clogf(zz); + /* multiply by 1/i = -i */ + w = zz * (-1.0f * I); + return w; +} diff --git a/lib/libm/complex/casinh.3 b/lib/libm/complex/casinh.3 new file mode 100644 index 0000000000..666f265f32 --- /dev/null +++ b/lib/libm/complex/casinh.3 @@ -0,0 +1,58 @@ +.\" $NetBSD: casinh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CASINH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" casinh +.SH NAME +casinh, casinhf \- complex arc hyperbolic sine functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex casinh(double complex\fP \fIz\fP\fB); +.br +float complex casinhf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex arc hyperbolic sine of \fIz\fP, +with branch cuts outside the interval +[-\fIi\fP,\ +\fIi\fP] along the imaginary axis. +.SH RETURN VALUE +.LP +These functions return the complex arc hyperbolic sine value, +in the range of a strip mathematically unbounded along the +real axis and in the interval [-\fIi\fPpi/2,\ +\fIi\fPpi/2] along +the imaginary axis. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcsinh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/casinh.c b/lib/libm/complex/casinh.c new file mode 100644 index 0000000000..1e88095fa0 --- /dev/null +++ b/lib/libm/complex/casinh.c @@ -0,0 +1,42 @@ +/* $NetBSD: casinh.c,v 1.1 2007/08/20 16:01:31 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 + +double complex +casinh(double complex z) +{ + double complex w; + + w = -1.0 * I * casin(z * I); + return w; +} diff --git a/lib/libm/complex/casinhf.c b/lib/libm/complex/casinhf.c new file mode 100644 index 0000000000..8d4c8a490f --- /dev/null +++ b/lib/libm/complex/casinhf.c @@ -0,0 +1,42 @@ +/* $NetBSD: casinhf.c,v 1.1 2007/08/20 16:01:32 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 + +float complex +casinhf(float complex z) +{ + float complex w; + + w = -1.0f * I * casinf(z * I); + return w; +} diff --git a/lib/libm/complex/catan.3 b/lib/libm/complex/catan.3 new file mode 100644 index 0000000000..a030ece492 --- /dev/null +++ b/lib/libm/complex/catan.3 @@ -0,0 +1,58 @@ +.\" $NetBSD: catan.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CATAN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" catan +.SH NAME +catan, catanf \- complex arc tangent functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex catan(double complex\fP \fIz\fP\fB); +.br +float complex catanf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex arc tangent of \fIz\fP, +with branch cuts outside the interval +[-\fIi\fP,\ +\fIi\fP] along the imaginary axis. +.SH RETURN VALUE +.LP +These functions return 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 +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIctan\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/catan.c b/lib/libm/complex/catan.c new file mode 100644 index 0000000000..d8c3cb4cd8 --- /dev/null +++ b/lib/libm/complex/catan.c @@ -0,0 +1,79 @@ +/* $NetBSD: catan.c,v 1.1 2007/08/20 16:01:32 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 +#include "cephes_subr.h" + +#ifdef __weak_alias +__weak_alias(catan, _catan) +#endif + +#define MAXNUM 1.0e308 + +double complex +catan(double complex z) +{ + double complex w; + double a, t, x, x2, y; + + x = creal(z); + y = cimag(z); + + if ((x == 0.0) && (y > 1.0)) + goto ovrf; + + x2 = x * x; + a = 1.0 - x2 - (y * y); + if (a == 0.0) + goto ovrf; + + t = 0.5 * atan2(2.0 * x, a); + w = _redupi(t); + + t = y - 1.0; + a = x2 + (t * t); + if (a == 0.0) + goto ovrf; + + t = y + 1.0; + a = (x2 + (t * t))/a; + w = w + (0.25 * log(a)) * I; + return w; + +ovrf: +#if 0 + mtherr ("catan", OVERFLOW); +#endif + w = MAXNUM + MAXNUM * I; + return w; +} diff --git a/lib/libm/complex/catanf.c b/lib/libm/complex/catanf.c new file mode 100644 index 0000000000..f280cbc41b --- /dev/null +++ b/lib/libm/complex/catanf.c @@ -0,0 +1,79 @@ +/* $NetBSD: catanf.c,v 1.1 2007/08/20 16:01:32 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 +#include "cephes_subrf.h" + +#ifdef __weak_alias +__weak_alias(catanf, _catanf) +#endif + +#define MAXNUMF 1.0e38F + +float complex +catanf(float complex z) +{ + float complex w; + float a, t, x, x2, y; + + x = crealf(z); + y = cimagf(z); + + if ((x == 0.0f) && (y > 1.0f)) + goto ovrf; + + x2 = x * x; + a = 1.0f - x2 - (y * y); + if (a == 0.0f) + goto ovrf; + + t = 0.5f * atan2f(2.0f * x, a); + w = _redupif(t); + + t = y - 1.0f; + a = x2 + (t * t); + if (a == 0.0f) + goto ovrf; + + t = y + 1.0f; + a = (x2 + (t * t))/a; + w = w + (0.25f * logf(a)) * I; + return w; + +ovrf: +#if 0 + mtherr ("catan", OVERFLOW); +#endif + w = MAXNUMF + MAXNUMF * I; + return w; +} diff --git a/lib/libm/complex/catanh.3 b/lib/libm/complex/catanh.3 new file mode 100644 index 0000000000..489ca8878c --- /dev/null +++ b/lib/libm/complex/catanh.3 @@ -0,0 +1,58 @@ +.\" $NetBSD: catanh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CATANH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" catanh +.SH NAME +catanh, catanhf \- complex arc hyperbolic tangent functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex catanh(double complex\fP \fIz\fP\fB); +.br +float complex catanhf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex arc hyperbolic tangent of +\fIz\fP, with branch cuts outside the interval +[-1,\ +1] along the real axis. +.SH RETURN VALUE +.LP +These functions return the complex arc hyperbolic tangent value, +in the range of a strip mathematically unbounded along +the real axis and in the interval [-\fIi\fPpi/2,\ +\fIi\fPpi/2] along +the imaginary axis. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIctanh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/catanh.c b/lib/libm/complex/catanh.c new file mode 100644 index 0000000000..99b3fbb8d4 --- /dev/null +++ b/lib/libm/complex/catanh.c @@ -0,0 +1,42 @@ +/* $NetBSD: catanh.c,v 1.1 2007/08/20 16:01:32 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 + +double complex +catanh(double complex z) +{ + double complex w; + + w = -1.0 * I * catan(z * I); + return w; +} diff --git a/lib/libm/complex/catanhf.c b/lib/libm/complex/catanhf.c new file mode 100644 index 0000000000..094a2b64fe --- /dev/null +++ b/lib/libm/complex/catanhf.c @@ -0,0 +1,42 @@ +/* $NetBSD: catanhf.c,v 1.1 2007/08/20 16:01:32 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 + +float complex +catanhf(float complex z) +{ + float complex w; + + w = -1.0f * I * catanf(z * I); + return w; +} diff --git a/lib/libm/complex/ccos.3 b/lib/libm/complex/ccos.3 new file mode 100644 index 0000000000..c952a83cf0 --- /dev/null +++ b/lib/libm/complex/ccos.3 @@ -0,0 +1,53 @@ +.\" $NetBSD: ccos.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CCOS" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" ccos +.SH NAME +ccos, ccosf \- complex cosine functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex ccos(double complex\fP \fIz\fP\fB); +.br +float complex ccosf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex cosine of \fIz\fP. +.SH RETURN VALUE +.LP +These functions return the complex cosine value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcacos\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/ccos.c b/lib/libm/complex/ccos.c new file mode 100644 index 0000000000..4b92ea44a5 --- /dev/null +++ b/lib/libm/complex/ccos.c @@ -0,0 +1,46 @@ +/* $NetBSD: ccos.c,v 1.1 2007/08/20 16:01:32 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 +#include "cephes_subr.h" + +double complex +ccos(double complex z) +{ + double complex w; + double ch, sh; + + _cchsh(cimag(z), &ch, &sh); + w = cos(creal(z)) * ch - (sin(creal(z)) * sh) * I; + return w; +} diff --git a/lib/libm/complex/ccosf.c b/lib/libm/complex/ccosf.c new file mode 100644 index 0000000000..32abc63f82 --- /dev/null +++ b/lib/libm/complex/ccosf.c @@ -0,0 +1,46 @@ +/* $NetBSD: ccosf.c,v 1.1 2007/08/20 16:01:33 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 +#include "cephes_subrf.h" + +float complex +ccosf(float complex z) +{ + float complex w; + float ch, sh; + + _cchshf(cimagf(z), &ch, &sh); + w = cosf(crealf(z)) * ch - (sinf(crealf(z)) * sh) * I; + return w; +} diff --git a/lib/libm/complex/ccosh.3 b/lib/libm/complex/ccosh.3 new file mode 100644 index 0000000000..e073360b93 --- /dev/null +++ b/lib/libm/complex/ccosh.3 @@ -0,0 +1,53 @@ +.\" $NetBSD: ccosh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CCOSH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" ccosh +.SH NAME +ccosh, ccoshf \- complex hyperbolic cosine functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex ccosh(double complex\fP \fIz\fP\fB); +.br +float complex ccoshf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex hyperbolic cosine of \fIz\fP. +.SH RETURN VALUE +.LP +These functions return the complex hyperbolic cosine value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcacosh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/ccosh.c b/lib/libm/complex/ccosh.c new file mode 100644 index 0000000000..1a5c91319b --- /dev/null +++ b/lib/libm/complex/ccosh.c @@ -0,0 +1,46 @@ +/* $NetBSD: ccosh.c,v 1.1 2007/08/20 16:01:33 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 + +double complex +ccosh(double complex z) +{ + double complex w; + double x, y; + + x = creal(z); + y = cimag(z); + w = cosh(x) * cos(y) + (sinh(x) * sin(y)) * I; + return w; +} diff --git a/lib/libm/complex/ccoshf.c b/lib/libm/complex/ccoshf.c new file mode 100644 index 0000000000..690c8bca9b --- /dev/null +++ b/lib/libm/complex/ccoshf.c @@ -0,0 +1,46 @@ +/* $NetBSD: ccoshf.c,v 1.1 2007/08/20 16:01:33 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 + +float complex +ccoshf(float complex z) +{ + float complex w; + float x, y; + + x = crealf(z); + y = cimagf(z); + w = coshf(x) * cosf(y) + (sinhf(x) * sinf(y)) * I; + return w; +} diff --git a/lib/libm/complex/cephes_subr.c b/lib/libm/complex/cephes_subr.c new file mode 100644 index 0000000000..c6e14912df --- /dev/null +++ b/lib/libm/complex/cephes_subr.c @@ -0,0 +1,124 @@ +/* $NetBSD: cephes_subr.c,v 1.1 2007/08/20 16:01:33 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 +#include "cephes_subr.h" + +/* calculate cosh and sinh */ + +void +_cchsh(double x, double *c, double *s) +{ + double e, ei; + + if (fabs(x) <= 0.5) { + *c = cosh(x); + *s = sinh(x); + } else { + e = exp(x); + ei = 0.5 / e; + e = 0.5 * e; + *s = e - ei; + *c = e + ei; + } +} + +/* Program to subtract nearest integer multiple of PI */ + +/* extended precision value of PI: */ +static const double DP1 = 3.14159265160560607910E0; +static const double DP2 = 1.98418714791870343106E-9; +static const double DP3 = 1.14423774522196636802E-17; +#define MACHEP 1.1e-16 + +double +_redupi(double x) +{ + double t; + long i; + + t = x / M_PI; + if (t >= 0.0) + t += 0.5; + else + t -= 0.5; + + i = t; /* the multiple */ + t = i; + t = ((x - t * DP1) - t * DP2) - t * DP3; + return t; +} + +/* Taylor series expansion for cosh(2y) - cos(2x) */ + +double +_ctans(double complex z) +{ + double f, x, x2, y, y2, rn, t; + double d; + + x = fabs(2.0 * creal(z)); + y = fabs(2.0 * cimag(z)); + + x = _redupi(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.0; + f *= rn; + rn += 1.0; + f *= rn; + x2 *= x; + y2 *= y; + t = y2 + x2; + t /= f; + d += t; + + rn += 1.0; + f *= rn; + rn += 1.0; + f *= rn; + x2 *= x; + y2 *= y; + t = y2 - x2; + t /= f; + d += t; + } while (fabs(t/d) > MACHEP); + return d; +} diff --git a/lib/libm/complex/cephes_subr.h b/lib/libm/complex/cephes_subr.h new file mode 100644 index 0000000000..7d230525f3 --- /dev/null +++ b/lib/libm/complex/cephes_subr.h @@ -0,0 +1,5 @@ +/* $NetBSD: cephes_subr.h,v 1.1 2007/08/20 16:01:33 drochner Exp $ */ + +void _cchsh(double, double *, double *); +double _redupi(double); +double _ctans(double complex); diff --git a/lib/libm/complex/cephes_subrf.c b/lib/libm/complex/cephes_subrf.c new file mode 100644 index 0000000000..6b0192ff42 --- /dev/null +++ b/lib/libm/complex/cephes_subrf.c @@ -0,0 +1,123 @@ +/* $NetBSD: cephes_subrf.c,v 1.1 2007/08/20 16:01:34 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 +#include "cephes_subrf.h" + +/* calculate cosh and sinh */ + +void +_cchshf(float x, float *c, float *s) +{ + float e, ei; + + if (fabsf(x) <= 0.5f) { + *c = coshf(x); + *s = sinhf(x); + } else { + e = expf(x); + ei = 0.5f / e; + e = 0.5f * e; + *s = e - ei; + *c = e + ei; + } +} + +/* Program to subtract nearest integer multiple of PI */ + +/* extended precision value of PI: */ +static const double DP1 = 3.140625; +static const double DP2 = 9.67502593994140625E-4; +static const double DP3 = 1.509957990978376432E-7; +#define MACHEPF 3.0e-8 + +float +_redupif(float x) +{ + float t; + long i; + + t = x / (float)M_PI; + if (t >= 0.0f) + t += 0.5f; + else + t -= 0.5f; + + i = t; /* the multiple */ + t = i; + t = ((x - t * DP1) - t * DP2) - t * DP3; + return t; +} + +/* Taylor series expansion for cosh(2y) - cos(2x) */ + +float +_ctansf(float complex z) +{ + float f, x, x2, y, y2, rn, t, d; + + x = fabsf(2.0f * crealf(z)); + y = fabsf(2.0f * cimagf(z)); + + x = _redupif(x); + + x = x * x; + y = y * y; + x2 = 1.0f; + y2 = 1.0f; + f = 1.0f; + rn = 0.0f; + d = 0.0f; + do { + rn += 1.0f; + f *= rn; + rn += 1.0f; + f *= rn; + x2 *= x; + y2 *= y; + t = y2 + x2; + t /= f; + d += t; + + rn += 1.0f; + f *= rn; + rn += 1.0f; + f *= rn; + x2 *= x; + y2 *= y; + t = y2 - x2; + t /= f; + d += t; + } while (fabsf(t/d) > MACHEPF); + return d; +} diff --git a/lib/libm/complex/cephes_subrf.h b/lib/libm/complex/cephes_subrf.h new file mode 100644 index 0000000000..81aec46304 --- /dev/null +++ b/lib/libm/complex/cephes_subrf.h @@ -0,0 +1,5 @@ +/* $NetBSD: cephes_subrf.h,v 1.1 2007/08/20 16:01:34 drochner Exp $ */ + +void _cchshf(float, float *, float *); +float _redupif(float); +float _ctansf(float complex); diff --git a/lib/libm/complex/cexp.3 b/lib/libm/complex/cexp.3 new file mode 100644 index 0000000000..71c170b908 --- /dev/null +++ b/lib/libm/complex/cexp.3 @@ -0,0 +1,54 @@ +.\" $NetBSD: cexp.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CEXP" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" cexp +.SH NAME +cexp, cexpf \- complex exponential functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex cexp(double complex\fP \fIz\fP\fB); +.br +float complex cexpf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex exponent of \fIz\fP, defined +as \fIe**z\fP. +.SH RETURN VALUE +.LP +These functions return the complex exponential value of \fIz\fP. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIclog\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/cexp.c b/lib/libm/complex/cexp.c new file mode 100644 index 0000000000..e329110429 --- /dev/null +++ b/lib/libm/complex/cexp.c @@ -0,0 +1,47 @@ +/* $NetBSD: cexp.c,v 1.1 2007/08/20 16:01:34 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 + +double complex +cexp(double complex z) +{ + double complex w; + double r, x, y; + + x = creal(z); + y = cimag(z); + r = exp(x); + w = r * cos(y) + r * sin(y) * I; + return w; +} diff --git a/lib/libm/complex/cexpf.c b/lib/libm/complex/cexpf.c new file mode 100644 index 0000000000..ba7390b90d --- /dev/null +++ b/lib/libm/complex/cexpf.c @@ -0,0 +1,47 @@ +/* $NetBSD: cexpf.c,v 1.1 2007/08/20 16:01:34 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 + +float complex +cexpf(float complex z) +{ + float complex w; + float r, x, y; + + x = crealf(z); + y = cimagf(z); + r = expf(x); + w = r * cosf(y) + r * sinf(y) * I; + return w; +} diff --git a/lib/libm/complex/cimag.3 b/lib/libm/complex/cimag.3 new file mode 100644 index 0000000000..a7c9c8747d --- /dev/null +++ b/lib/libm/complex/cimag.3 @@ -0,0 +1,61 @@ +.\" $NetBSD: cimag.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CIMAG" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" cimag +.SH NAME +cimag, cimagf \- complex imaginary functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double cimag(double complex\fP \fIz\fP\fB); +.br +float cimagf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the imaginary part of \fIz\fP. +.SH RETURN VALUE +.LP +These functions return the imaginary part value (as a real). +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +For a variable \fIz\fP of complex type: +.sp +.RS +.nf + +\fBz == creal(z) + cimag(z)*I +\fP +.fi +.RE +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcarg\fP(), \fIconj\fP(), \fIcproj\fP(), \fIcreal\fP(), the +Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP +.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/include/complex.h b/lib/libm/complex/cimag.c similarity index 56% copy from include/complex.h copy to lib/libm/complex/cimag.c index f975c5ab72..0645fbf74f 100644 --- a/include/complex.h +++ b/lib/libm/complex/cimag.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include +#include "../src/math_private.h" -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif +double +cimag(double complex z) +{ + const double_complex z1 = { .f = z }; -#define complex _Complex -#define I _Complex_I - -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ + return (IMAGPART(z1)); +} diff --git a/include/complex.h b/lib/libm/complex/cimagf.c similarity index 56% copy from include/complex.h copy to lib/libm/complex/cimagf.c index f975c5ab72..973da2afd8 100644 --- a/include/complex.h +++ b/lib/libm/complex/cimagf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include +#include "../src/math_private.h" -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif +float +cimagf(float complex z) +{ + const float_complex z1 = { .f = z }; -#define complex _Complex -#define I _Complex_I - -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ + return (IMAGPART(z1)); +} diff --git a/include/complex.h b/lib/libm/complex/cimagl.c similarity index 56% copy from include/complex.h copy to lib/libm/complex/cimagl.c index f975c5ab72..e7ada1b9f9 100644 --- a/include/complex.h +++ b/lib/libm/complex/cimagl.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include +#include "../src/math_private.h" -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif +long double +cimagl(long double complex z) +{ + const long_double_complex z1 = { .f = z }; -#define complex _Complex -#define I _Complex_I - -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ + return (IMAGPART(z1)); +} diff --git a/lib/libm/complex/clog.3 b/lib/libm/complex/clog.3 new file mode 100644 index 0000000000..d5460e4077 --- /dev/null +++ b/lib/libm/complex/clog.3 @@ -0,0 +1,58 @@ +.\" $NetBSD: clog.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CLOG" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" clog +.SH NAME +clog, clogf \- complex natural logarithm functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex clog(double complex\fP \fIz\fP\fB); +.br +float complex clogf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex natural (base \fIe\fP) logarithm +of \fIz\fP, with a branch cut along the negative +real axis. +.SH RETURN VALUE +.LP +These functions return the complex natural logarithm value, +in the range of a strip mathematically unbounded along the +real axis and in the interval [-\fIi\fPpi,\ +\fIi\fPpi] along the +imaginary axis. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcexp\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/clog.c b/lib/libm/complex/clog.c new file mode 100644 index 0000000000..2165f63a57 --- /dev/null +++ b/lib/libm/complex/clog.c @@ -0,0 +1,47 @@ +/* $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 + +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/complex/clogf.c b/lib/libm/complex/clogf.c new file mode 100644 index 0000000000..1c718baf1e --- /dev/null +++ b/lib/libm/complex/clogf.c @@ -0,0 +1,47 @@ +/* $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 + +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/complex/conj.3 b/lib/libm/complex/conj.3 new file mode 100644 index 0000000000..7048b6be9f --- /dev/null +++ b/lib/libm/complex/conj.3 @@ -0,0 +1,54 @@ +.\" $NetBSD: conj.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CONJ" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" conj +.SH NAME +conj, conjf \- complex conjugate functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex conj(double complex\fP \fIz\fP\fB); +.br +float complex conjf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex conjugate of \fIz\fP, by +reversing the sign of its imaginary part. +.SH RETURN VALUE +.LP +These functions return the complex conjugate value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcarg\fP(), \fIcimag\fP(), \fIcproj\fP(), \fIcreal\fP(), the +Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP +.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/include/complex.h b/lib/libm/complex/conj.c similarity index 56% copy from include/complex.h copy to lib/libm/complex/conj.c index f975c5ab72..7a79bf8f03 100644 --- a/include/complex.h +++ b/lib/libm/complex/conj.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif +#include "../src/math_private.h" -#define complex _Complex -#define I _Complex_I +double complex +conj(double complex z) +{ -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ + return (cpack(creal(z), -cimag(z))); +} diff --git a/include/complex.h b/lib/libm/complex/conjf.c similarity index 56% copy from include/complex.h copy to lib/libm/complex/conjf.c index f975c5ab72..d26314cdc0 100644 --- a/include/complex.h +++ b/lib/libm/complex/conjf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif +#include "../src/math_private.h" -#define complex _Complex -#define I _Complex_I +float complex +conjf(float complex z) +{ -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ + return (cpackf(crealf(z), -cimagf(z))); +} diff --git a/include/complex.h b/lib/libm/complex/conjl.c similarity index 56% copy from include/complex.h copy to lib/libm/complex/conjl.c index f975c5ab72..4555206895 100644 --- a/include/complex.h +++ b/lib/libm/complex/conjl.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif +#include "../src/math_private.h" -#define complex _Complex -#define I _Complex_I +long double complex +conjl(long double complex z) +{ -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ + return (cpackl(creall(z), -cimagl(z))); +} diff --git a/lib/libm/complex/cpow.3 b/lib/libm/complex/cpow.3 new file mode 100644 index 0000000000..5c78e368ca --- /dev/null +++ b/lib/libm/complex/cpow.3 @@ -0,0 +1,57 @@ +.\" $NetBSD: cpow.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CPOW" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" cpow +.SH NAME +cpow, cpowf \- complex power functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex cpow(double complex\fP \fIx\fP\fB, double complex\fP +\fIy\fP\fB); +.br +float complex cpowf(float complex\fP \fIx\fP\fB, float complex\fP +\fIy\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex power function \fIx**y\fP, +with a branch cut for the first +parameter along the negative real axis. +.SH RETURN VALUE +.LP +These functions return the complex power function value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcabs\fP(), \fIcsqrt\fP(), the Base Definitions volume of +IEEE\ Std\ 1003.1-2001, \fI\fP +.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/complex/cpow.c b/lib/libm/complex/cpow.c new file mode 100644 index 0000000000..e9e1179910 --- /dev/null +++ b/lib/libm/complex/cpow.c @@ -0,0 +1,57 @@ +/* $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 + +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/complex/cpowf.c b/lib/libm/complex/cpowf.c new file mode 100644 index 0000000000..c195ffa4c1 --- /dev/null +++ b/lib/libm/complex/cpowf.c @@ -0,0 +1,57 @@ +/* $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 + +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/include/complex.h b/lib/libm/complex/cproj.c similarity index 64% copy from include/complex.h copy to lib/libm/complex/cproj.c index f975c5ab72..253f5e8eca 100644 --- a/include/complex.h +++ b/lib/libm/complex/cproj.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2008 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,40 +22,26 @@ * 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. - * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H - -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif - -#define complex _Complex -#define I _Complex_I - #include -__BEGIN_DECLS +#include +#include + +#include "../src/math_private.h" -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); +double complex +cproj(double complex z) +{ -__END_DECLS + if (!isinf(creal(z)) && !isinf(cimag(z))) + return (z); + else + return (cpack(INFINITY, copysign(0.0, cimag(z)))); +} -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) +#if LDBL_MANT_DIG == 53 +__weak_reference(cproj, cprojl); #endif -#endif /* _COMPLEX_H */ diff --git a/include/complex.h b/lib/libm/complex/cprojf.c similarity index 64% copy from include/complex.h copy to lib/libm/complex/cprojf.c index f975c5ab72..d98864df25 100644 --- a/include/complex.h +++ b/lib/libm/complex/cprojf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2008 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,40 +22,21 @@ * 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. - * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H - -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif - -#define complex _Complex -#define I _Complex_I - #include -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); +#include +#include -__END_DECLS +#include "../src/math_private.h" -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif +float complex +cprojf(float complex z) +{ -#endif /* _COMPLEX_H */ + if (!isinf(crealf(z)) && !isinf(cimagf(z))) + return (z); + else + return (cpackf(INFINITY, copysignf(0.0, cimagf(z)))); +} diff --git a/include/complex.h b/lib/libm/complex/cprojl.c similarity index 64% copy from include/complex.h copy to lib/libm/complex/cprojl.c index f975c5ab72..ec90b5a557 100644 --- a/include/complex.h +++ b/lib/libm/complex/cprojl.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2008 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,40 +22,21 @@ * 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. - * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H - -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif - -#define complex _Complex -#define I _Complex_I - #include -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); +#include +#include -__END_DECLS +#include "../src/math_private.h" -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif +long double complex +cprojl(long double complex z) +{ -#endif /* _COMPLEX_H */ + if (!isinf(creall(z)) && !isinf(cimagl(z))) + return (z); + else + return (cpackl(INFINITY, copysignl(0.0, cimagl(z)))); +} diff --git a/lib/libm/complex/creal.3 b/lib/libm/complex/creal.3 new file mode 100644 index 0000000000..842c821f4d --- /dev/null +++ b/lib/libm/complex/creal.3 @@ -0,0 +1,61 @@ +.\" $NetBSD: creal.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CREAL" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" creal +.SH NAME +creal, crealf \- complex real functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double creal(double complex\fP \fIz\fP\fB); +.br +float crealf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the real part of \fIz\fP. +.SH RETURN VALUE +.LP +These functions return the real part value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +For a variable \fIz\fP of type \fBcomplex\fP: +.sp +.RS +.nf + +\fBz == creal(z) + cimag(z)*I +\fP +.fi +.RE +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcarg\fP(), \fIcimag\fP(), \fIconj\fP(), \fIcproj\fP(), the +Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP +.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/include/complex.h b/lib/libm/complex/creal.c similarity index 56% copy from include/complex.h copy to lib/libm/complex/creal.c index f975c5ab72..3295ff281b 100644 --- a/include/complex.h +++ b/lib/libm/complex/creal.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif - -#define complex _Complex -#define I _Complex_I - -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ +double +creal(double complex z) +{ + return z; +} diff --git a/include/complex.h b/lib/libm/complex/crealf.c similarity index 56% copy from include/complex.h copy to lib/libm/complex/crealf.c index f975c5ab72..5819b86b79 100644 --- a/include/complex.h +++ b/lib/libm/complex/crealf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif - -#define complex _Complex -#define I _Complex_I - -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ +float +crealf(float complex z) +{ + return z; +} diff --git a/include/complex.h b/lib/libm/complex/creall.c similarity index 56% copy from include/complex.h copy to lib/libm/complex/creall.c index f975c5ab72..e4946f9fd0 100644 --- a/include/complex.h +++ b/lib/libm/complex/creall.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif - -#define complex _Complex -#define I _Complex_I - -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ +long double +creall(long double complex z) +{ + return z; +} diff --git a/lib/libm/complex/csin.3 b/lib/libm/complex/csin.3 new file mode 100644 index 0000000000..69394eb21a --- /dev/null +++ b/lib/libm/complex/csin.3 @@ -0,0 +1,53 @@ +.\" $NetBSD: csin.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CSIN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" csin +.SH NAME +csin, csinf \- complex sine functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex csin(double complex\fP \fIz\fP\fB); +.br +float complex csinf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex sine of \fIz\fP. +.SH RETURN VALUE +.LP +These functions return the complex sine value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcasin\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/csin.c b/lib/libm/complex/csin.c new file mode 100644 index 0000000000..e09b5cbf03 --- /dev/null +++ b/lib/libm/complex/csin.c @@ -0,0 +1,46 @@ +/* $NetBSD: csin.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 +#include "cephes_subr.h" + +double complex +csin(double complex z) +{ + double complex w; + double ch, sh; + + _cchsh(cimag(z), &ch, &sh); + w = sin(creal(z)) * ch + (cos(creal(z)) * sh) * I; + return w; +} diff --git a/lib/libm/complex/csinf.c b/lib/libm/complex/csinf.c new file mode 100644 index 0000000000..4ff8fed320 --- /dev/null +++ b/lib/libm/complex/csinf.c @@ -0,0 +1,46 @@ +/* $NetBSD: csinf.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 +#include "cephes_subrf.h" + +float complex +csinf(float complex z) +{ + float complex w; + float ch, sh; + + _cchshf(cimagf(z), &ch, &sh); + w = sinf(crealf(z)) * ch + (cosf(crealf(z)) * sh) * I; + return w; +} diff --git a/lib/libm/complex/csinh.3 b/lib/libm/complex/csinh.3 new file mode 100644 index 0000000000..ad2e2226c4 --- /dev/null +++ b/lib/libm/complex/csinh.3 @@ -0,0 +1,53 @@ +.\" $NetBSD: csinh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CSINH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" csinh +.SH NAME +csinh, csinhf \- complex hyperbolic sine functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex csinh(double complex\fP \fIz\fP\fB); +.br +float complex csinhf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex hyperbolic sine of \fIz\fP. +.SH RETURN VALUE +.LP +These functions return the complex hyperbolic sine value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcasinh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/csinh.c b/lib/libm/complex/csinh.c new file mode 100644 index 0000000000..6845e5e796 --- /dev/null +++ b/lib/libm/complex/csinh.c @@ -0,0 +1,46 @@ +/* $NetBSD: csinh.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 + +double complex +csinh(double complex z) +{ + double complex w; + double x, y; + + x = creal(z); + y = cimag(z); + w = sinh(x) * cos(y) + (cosh(x) * sin(y)) * I; + return w; +} diff --git a/lib/libm/complex/csinhf.c b/lib/libm/complex/csinhf.c new file mode 100644 index 0000000000..0bbe5a3b2b --- /dev/null +++ b/lib/libm/complex/csinhf.c @@ -0,0 +1,46 @@ +/* $NetBSD: csinhf.c,v 1.1 2007/08/20 16:01:37 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 + +float complex +csinhf(float complex z) +{ + float complex w; + float x, y; + + x = crealf(z); + y = cimagf(z); + w = sinhf(x) * cosf(y) + (coshf(x) * sinf(y)) * I; + return w; +} diff --git a/lib/libm/complex/csqrt.3 b/lib/libm/complex/csqrt.3 new file mode 100644 index 0000000000..132daf9997 --- /dev/null +++ b/lib/libm/complex/csqrt.3 @@ -0,0 +1,56 @@ +.\" $NetBSD: csqrt.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CSQRT" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" csqrt +.SH NAME +csqrt, csqrtf \- complex square root functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex csqrt(double complex\fP \fIz\fP\fB); +.br +float complex csqrtf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex square root of \fIz\fP, +with a branch cut along the negative real axis. +.SH RETURN VALUE +.LP +These functions return the complex square root value, in the +range of the right half-plane (including the imaginary +axis). +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcabs\fP(), \fIcpow\fP(), the Base Definitions volume of +IEEE\ Std\ 1003.1-2001, \fI\fP +.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/complex/csqrt.c b/lib/libm/complex/csqrt.c new file mode 100644 index 0000000000..f9267ec13d --- /dev/null +++ b/lib/libm/complex/csqrt.c @@ -0,0 +1,99 @@ +/* $NetBSD: csqrt.c,v 1.1 2007/08/20 16:01:37 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 + +double complex +csqrt(double complex z) +{ + double complex w; + double x, y, r, t, scale; + + x = creal (z); + y = cimag (z); + + if (y == 0.0) { + if (x == 0.0) { + w = 0.0 + y * I; + } else { + r = fabs(x); + r = sqrt(r); + if (x < 0.0) { + w = 0.0 + r * I; + } else { + w = r + y * I; + } + } + return w; + } + if (x == 0.0) { + r = fabs(y); + r = sqrt(0.5 * r); + if (y > 0) + w = r + r * I; + else + w = r - r * I; + return w; + } + /* Rescale to avoid internal overflow or underflow. */ + if ((fabs(x) > 4.0) || (fabs(y) > 4.0)) { + x *= 0.25; + y *= 0.25; + scale = 2.0; + } else { +#if 1 + x *= 1.8014398509481984e16; /* 2^54 */ + y *= 1.8014398509481984e16; + scale = 7.450580596923828125e-9; /* 2^-27 */ +#else + x *= 4.0; + y *= 4.0; + scale = 0.5; +#endif + } + w = x + y * I; + r = cabs(w); + if (x > 0) { + t = sqrt(0.5 * r + 0.5 * x); + r = scale * fabs((0.5 * y) / t ); + t *= scale; + } else { + r = sqrt(0.5 * r - 0.5 * x); + t = scale * fabs((0.5 * y) / r); + r *= scale; + } + if (y < 0) + w = t - r * I; + else + w = t + r * I; + return w; +} diff --git a/lib/libm/complex/csqrtf.c b/lib/libm/complex/csqrtf.c new file mode 100644 index 0000000000..a230430a87 --- /dev/null +++ b/lib/libm/complex/csqrtf.c @@ -0,0 +1,99 @@ +/* $NetBSD: csqrtf.c,v 1.1 2007/08/20 16:01:37 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 + +float complex +csqrtf(float complex z) +{ + float complex w; + float x, y, r, t, scale; + + x = crealf (z); + y = cimagf (z); + + if (y == 0.0f) { + if (x < 0.0f) { + w = 0.0f + sqrtf(-x) * I; + return w; + } else if (x == 0.0f) { + return (0.0f + y * I); + } else { + w = sqrtf(x) + y * I; + return w; + } + } + + if (x == 0.0f) { + r = fabsf(y); + r = sqrtf(0.5f * r); + if (y > 0) + w = r + r * I; + else + w = r - r * I; + return w; + } + + /* Rescale to avoid internal overflow or underflow. */ + if ((fabsf(x) > 4.0f) || (fabsf(y) > 4.0f)) { + x *= 0.25f; + y *= 0.25f; + scale = 2.0f; + } else { +#if 1 + x *= 6.7108864e7f; /* 2^26 */ + y *= 6.7108864e7f; + scale = 1.220703125e-4f; /* 2^-13 */ +#else + x *= 4.0f; + y *= 4.0f; + scale = 0.5f; +#endif + } + w = x + y * I; + r = cabsf(w); + if( x > 0 ) { + t = sqrtf(0.5f * r + 0.5f * x); + r = scale * fabsf((0.5f * y) / t); + t *= scale; + } else { + r = sqrtf(0.5f * r - 0.5f * x); + t = scale * fabsf((0.5f * y) / r); + r *= scale; + } + + if (y < 0) + w = t - r * I; + else + w = t + r * I; + return w; +} diff --git a/lib/libm/complex/ctan.3 b/lib/libm/complex/ctan.3 new file mode 100644 index 0000000000..02293c9773 --- /dev/null +++ b/lib/libm/complex/ctan.3 @@ -0,0 +1,53 @@ +.\" $NetBSD: ctan.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CTAN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" ctan +.SH NAME +ctan, ctanf \- complex tangent functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex ctan(double complex\fP \fIz\fP\fB); +.br +float complex ctanf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex tangent of \fIz\fP. +.SH RETURN VALUE +.LP +These functions return the complex tangent value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcatan\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/ctan.c b/lib/libm/complex/ctan.c new file mode 100644 index 0000000000..6e9673ba84 --- /dev/null +++ b/lib/libm/complex/ctan.c @@ -0,0 +1,58 @@ +/* $NetBSD: ctan.c,v 1.1 2007/08/20 16:01:37 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 +#include "cephes_subr.h" + +#define MAXNUM 1.0e308 + +double complex +ctan(double complex z) +{ + double complex w; + double d; + + d = cos(2.0 * creal(z)) + cosh(2.0 * cimag(z)); + + if (fabs(d) < 0.25) + d = _ctans(z); + + if (d == 0.0) { + /* mtherr ("ctan", OVERFLOW); */ + w = MAXNUM + MAXNUM * I; + return w; + } + + w = sin(2.0 * creal(z)) / d + (sinh(2.0 * cimag(z)) / d) * I; + return w; +} diff --git a/lib/libm/complex/ctanf.c b/lib/libm/complex/ctanf.c new file mode 100644 index 0000000000..1e0a170dbc --- /dev/null +++ b/lib/libm/complex/ctanf.c @@ -0,0 +1,58 @@ +/* $NetBSD: ctanf.c,v 1.1 2007/08/20 16:01:38 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 +#include "cephes_subrf.h" + +#define MAXNUMF 1.0e38f + +float complex +ctanf(float complex z) +{ + float complex w; + float d; + + d = cosf(2.0f * crealf(z)) + coshf(2.0f * cimagf(z)); + + if (fabsf(d) < 0.25f) + d = _ctansf(z); + + if (d == 0.0f) { + /* mtherr ("ctan", OVERFLOW); */ + w = MAXNUMF + MAXNUMF * I; + return w; + } + + w = sinf(2.0f * crealf(z)) / d + (sinhf(2.0f * cimagf(z)) / d) * I; + return w; +} diff --git a/lib/libm/complex/ctanh.3 b/lib/libm/complex/ctanh.3 new file mode 100644 index 0000000000..85c976e3f2 --- /dev/null +++ b/lib/libm/complex/ctanh.3 @@ -0,0 +1,53 @@ +.\" $NetBSD: ctanh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "CTANH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" ctanh +.SH NAME +ctanh, ctanhf \- complex hyperbolic tangent functions +.SH SYNOPSIS +.LP +\fB#include +.br +.sp +double complex ctanh(double complex\fP \fIz\fP\fB); +.br +float complex ctanhf(float complex\fP \fIz\fP\fB); +.br +\fP +.SH DESCRIPTION +.LP +These functions compute the complex hyperbolic tangent of \fIz\fP. +.SH RETURN VALUE +.LP +These functions return the complex hyperbolic tangent value. +.SH ERRORS +.LP +No errors are defined. +.LP +\fIThe following sections are informative.\fP +.SH EXAMPLES +.LP +None. +.SH APPLICATION USAGE +.LP +None. +.SH RATIONALE +.LP +None. +.SH FUTURE DIRECTIONS +.LP +None. +.SH SEE ALSO +.LP +\fIcatanh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, +\fI\fP +.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/complex/ctanh.c b/lib/libm/complex/ctanh.c new file mode 100644 index 0000000000..34c976a07a --- /dev/null +++ b/lib/libm/complex/ctanh.c @@ -0,0 +1,48 @@ +/* $NetBSD: ctanh.c,v 1.1 2007/08/20 16:01:38 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 + +double complex +ctanh(double complex z) +{ + double complex w; + double x, y, d; + + x = creal(z); + y = cimag(z); + d = cosh(2.0 * x) + cos(2.0 * y); + w = sinh(2.0 * x) / d + (sin(2.0 * y) / d) * I; + + return w; +} diff --git a/lib/libm/complex/ctanhf.c b/lib/libm/complex/ctanhf.c new file mode 100644 index 0000000000..d4197caae6 --- /dev/null +++ b/lib/libm/complex/ctanhf.c @@ -0,0 +1,48 @@ +/* $NetBSD: ctanhf.c,v 1.1 2007/08/20 16:01:38 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 + +float complex +ctanhf(float complex z) +{ + float complex w; + float x, y, d; + + x = crealf(z); + y = cimagf(z); + d = coshf(2.0f * x) + cosf(2.0f * y); + w = sinhf(2.0f * x) / d + (sinf(2.0f * y) / d) * I; + + return w; +} diff --git a/lib/libm/src/Makefile.inc b/lib/libm/src/Makefile.inc index 71574f6189..2bf342ed90 100644 --- a/lib/libm/src/Makefile.inc +++ b/lib/libm/src/Makefile.inc @@ -8,7 +8,7 @@ CFLAGS+=-I${LIBCDIR}/include -I${LIBCDIR}/${MACHINE_ARCH} # This files are always used. SRCS+= k_cos.c k_cosf.c k_rem_pio2.c k_rem_pio2f.c k_sin.c k_sinf.c \ k_tan.c k_tanf.c llrint.c llrintf.c llround.c \ - llroundf.c lrint.c lrintf.c lround.c lroundf.c s_trunc.c s_truncf.c w_cabs.c w_cabsf.c \ + llroundf.c lrint.c lrintf.c lround.c lroundf.c s_trunc.c s_truncf.c \ w_drem.c w_dremf.c w_gamma.c w_gamma_r.c w_gammaf.c w_gammaf_r.c \ w_lgamma.c w_lgammaf.c @@ -24,7 +24,7 @@ MI_FUNCS+= \ e_rem_pio2f.c e_remainder.c e_remainderf.c e_scalb.c e_scalbf.c \ e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c \ s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_cbrt.c s_cbrtf.c s_ceil.c \ - s_ceilf.c s_copysign.c s_copysignf.c s_cos.c s_cosf.c s_erf.c \ + s_ceilf.c s_copysign.c s_copysignf.c s_copysignl.c s_cos.c s_cosf.c s_erf.c \ s_erff.c s_expm1.c s_expm1f.c s_fabsf.c s_fdim.c s_finite.c \ s_finitef.c s_floor.c s_floorf.c s_fmax.c s_fmaxf.c s_fmaxl.c \ s_fmin.c s_fminf.c s_fminl.c s_frexpf.c s_frexpl.c s_ilogb.c \ diff --git a/lib/libm/src/math_private.h b/lib/libm/src/math_private.h index 675a9c5b6b..faa8834f9d 100644 --- a/lib/libm/src/math_private.h +++ b/lib/libm/src/math_private.h @@ -153,6 +153,70 @@ do { \ (d) = sf_u.value; \ } while (0) +#ifdef _COMPLEX_H + +/* + * C99 specifies that complex numbers have the same representation as + * an array of two elements, where the first element is the real part + * and the second element is the imaginary part. + */ +typedef union { + float complex f; + float a[2]; +} float_complex; +typedef union { + double complex f; + double a[2]; +} double_complex; +typedef union { + long double complex f; + long double a[2]; +} long_double_complex; +#define REALPART(z) ((z).a[0]) +#define IMAGPART(z) ((z).a[1]) + +/* + * Inline functions that can be used to construct complex values. + * + * The C99 standard intends x+I*y to be used for this, but x+I*y is + * currently unusable in general since gcc introduces many overflow, + * underflow, sign and efficiency bugs by rewriting I*y as + * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product. + * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted + * to -0.0+I*0.0. + */ +static __inline float complex +cpackf(float x, float y) +{ + float_complex z; + + REALPART(z) = x; + IMAGPART(z) = y; + return (z.f); +} + +static __inline double complex +cpack(double x, double y) +{ + double_complex z; + + REALPART(z) = x; + IMAGPART(z) = y; + return (z.f); +} + +static __inline long double complex +cpackl(long double x, long double y) +{ + long_double_complex z; + + REALPART(z) = x; + IMAGPART(z) = y; + return (z.f); +} + +#endif /* _COMPLEX_H */ + __BEGIN_DECLS #pragma GCC visibility push(hidden) diff --git a/include/complex.h b/lib/libm/src/s_copysignl.c similarity index 56% copy from include/complex.h copy to lib/libm/src/s_copysignl.c index f975c5ab72..8d39f841db 100644 --- a/include/complex.h +++ b/lib/libm/src/s_copysignl.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001 The FreeBSD Project. + * Copyright (c) 2004 Stefan Farfeleder * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR 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) @@ -23,39 +23,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD$ */ -#ifndef _COMPLEX_H -#define _COMPLEX_H +#include -#ifdef __GNUC__ -#define _Complex __complex__ -#define _Complex_I 1.0fi -#endif +#include "fpmath.h" -#define complex _Complex -#define I _Complex_I +long double +copysignl(long double x, long double y) +{ + union IEEEl2bits ux, uy; -#include - -__BEGIN_DECLS - -double cabs (double complex); -float cabsf (float complex); -double cimag (double complex); -float cimagf (float complex); -double creal (double complex); -float crealf (float complex); - -__END_DECLS - -#ifdef __GNUC__ -#define cimag(z) (__imag__ (z)) -#define cimagf(z) (__imag__ (z)) -#define creal(z) (__real__ (z)) -#define crealf(z) (__real__ (z)) -#endif - -#endif /* _COMPLEX_H */ + ux.e = x; + uy.e = y; + ux.bits.sign = uy.bits.sign; + return (ux.e); +} diff --git a/lib/libm/src/w_cabs.c b/lib/libm/src/w_cabs.c deleted file mode 100644 index 7e9318e575..0000000000 --- a/lib/libm/src/w_cabs.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * cabs() wrapper for hypot(). - * - * Written by J.T. Conklin, - * Placed into the Public Domain, 1994. - * - * $NetBSD: w_cabs.c,v 1.4 2001/01/06 00:15:00 christos Exp $ - * $DragonFly: src/lib/libm/src/w_cabs.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ - */ - -#include -#include - -double -cabs(double complex z) -{ - return hypot(creal(z), cimag(z)); -} diff --git a/lib/libm/src/w_cabsf.c b/lib/libm/src/w_cabsf.c deleted file mode 100644 index 8021b6e586..0000000000 --- a/lib/libm/src/w_cabsf.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * cabsf() wrapper for hypotf(). - * - * Written by J.T. Conklin, - * Placed into the Public Domain, 1994. - * - * $NetBSD: w_cabsf.c,v 1.4 2001/01/06 00:15:00 christos Exp $ - * $DragonFly: src/lib/libm/src/w_cabsf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ - */ - -#include -#include - -float -cabsf(float complex z) -{ - return hypot(crealf(z), cimagf(z)); -}