From 76fca99bc242eeae78173bde7f489730ecc9bc4b Mon Sep 17 00:00:00 2001 From: Gordon Bergling Date: Tue, 3 Sep 2019 08:33:24 +0200 Subject: [PATCH] Math(3): Implement complex arithmetic functions and her hyperbolic counterparts --- lib/msun/Makefile | 15 +++- lib/msun/man/ccos.3 | 5 +- lib/msun/man/ccosh.3 | 5 +- lib/msun/man/csin.3 | 76 +++++++++++++++++++ lib/msun/man/csinh.3 | 74 +++++++++++++++++++ lib/msun/man/ctan.3 | 82 ++++++++++++++++++++ lib/msun/man/ctanh.3 | 76 +++++++++++++++++++ lib/msun/src/s_ccos.c | 89 ++++++++++++++++++++++ lib/msun/src/s_ccosf.c | 88 ++++++++++++++++++++++ lib/msun/src/s_ccoshl.c | 62 ++++++++++++++++ lib/msun/src/s_ccosl.c | 85 +++++++++++++++++++++ lib/msun/src/s_csinhl.c | 61 +++++++++++++++ lib/msun/src/s_csinl.c | 87 ++++++++++++++++++++++ lib/msun/src/s_ctanhl.c | 63 ++++++++++++++++ lib/msun/src/s_ctanl.c | 160 ++++++++++++++++++++++++++++++++++++++++ 15 files changed, 1022 insertions(+), 6 deletions(-) create mode 100644 lib/msun/man/csin.3 create mode 100644 lib/msun/man/csinh.3 create mode 100644 lib/msun/man/ctan.3 create mode 100644 lib/msun/man/ctanh.3 create mode 100644 lib/msun/src/s_ccos.c create mode 100644 lib/msun/src/s_ccosf.c create mode 100644 lib/msun/src/s_ccoshl.c create mode 100644 lib/msun/src/s_ccosl.c create mode 100644 lib/msun/src/s_csinhl.c create mode 100644 lib/msun/src/s_csinl.c create mode 100644 lib/msun/src/s_ctanhl.c create mode 100644 lib/msun/src/s_ctanl.c diff --git a/lib/msun/Makefile b/lib/msun/Makefile index 6c9af4c018c..905062ec9eb 100644 --- a/lib/msun/Makefile +++ b/lib/msun/Makefile @@ -126,7 +126,9 @@ COMMON_SRCS+= catrig.c catrigf.c \ s_conj.c s_conjf.c s_conjl.c \ s_cpow.c s_cpowf.c s_cpowl.c \ s_cproj.c s_cprojf.c s_creal.c s_crealf.c s_creall.c \ - s_csinh.c s_csinhf.c s_ctanh.c s_ctanhf.c + s_csinh.c s_csinhf.c s_csinhl.c s_csinl.c \ + s_ctanh.c s_ctanhf.c s_ctanhl.c s_ctanl.c \ + s_ccoshl.c s_ccosl.c s_ccosf.c s_ccos.c # FreeBSD's C library supplies these functions: #COMMON_SRCS+= s_fabs.c s_frexp.c s_isnan.c s_ldexp.c s_modf.c @@ -153,7 +155,7 @@ MAN= acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 \ nextafter.3 remainder.3 rint.3 \ round.3 scalbn.3 signbit.3 sin.3 sincos.3 \ sinh.3 sqrt.3 tan.3 tanh.3 trunc.3 \ - complex.3 + complex.3 csin.3 csinh.3 ctan.3 ctanh.3 MLINKS+=acos.3 acosf.3 acos.3 acosl.3 MLINKS+=acosh.3 acoshf.3 acosh.3 acoshl.3 @@ -169,9 +171,10 @@ MLINKS+=cacos.3 cacosf.3 cacos.3 cacosl.3 \ cacos.3 casinh.3 cacos.3 casinhf.3 cacos.3 casinhl.3 \ cacos.3 catan.3 cacos.3 catanf.3 cacos.3 catanl.3 \ cacos.3 catanh.3 cacos.3 catanhf.3 cacos.3 catanhl.3 -MLINKS+=ccos.3 ccosf.3 ccos.3 csin.3 ccos.3 csinf.3 ccos.3 ctan.3 ccos.3 ctanf.3 +MLINKS+=ccos.3 ccosf.3 ccos.3 csin.3 ccos.3 csinf.3 ccos.3 ctan.3 \ + ccos.3 ctanf.3 ccos.3 ccosl.3 ccos.3 ccosf.3 MLINKS+=ccosh.3 ccoshf.3 ccosh.3 csinh.3 ccosh.3 csinhf.3 \ - ccosh.3 ctanh.3 ccosh.3 ctanhf.3 + ccosh.3 ctanh.3 ccosh.3 ctanhf.3 ccosh.3 ccoshl.3 MLINKS+=ceil.3 ceilf.3 ceil.3 ceill.3 MLINKS+=cexp.3 cexpf.3 MLINKS+=cimag.3 cimagf.3 cimag.3 cimagl.3 \ @@ -239,6 +242,10 @@ MLINKS+=sqrt.3 cbrt.3 sqrt.3 cbrtf.3 sqrt.3 cbrtl.3 sqrt.3 sqrtf.3 \ MLINKS+=tan.3 tanf.3 tan.3 tanl.3 MLINKS+=tanh.3 tanhf.3 tanh.3 tanhl.3 MLINKS+=trunc.3 truncf.3 trunc.3 truncl.3 +MLINKS+=csin.3 csinf.3 csin.3 csinl.3 +MLINKS+=csinh.3 csinhf.3 csinh.3 csinhl.3 +MLINKS+=ctan.3 ctanf.3 ctan.3 ctanl.3 +MLINKS+=ctanh.3 ctanhf.3 ctanh.3 ctanhl.3 .include diff --git a/lib/msun/man/ccos.3 b/lib/msun/man/ccos.3 index c07205e6d91..8445c26b459 100644 --- a/lib/msun/man/ccos.3 +++ b/lib/msun/man/ccos.3 @@ -24,12 +24,13 @@ .\" .\" $FreeBSD$ .\" -.Dd October 17, 2011 +.Dd September 2, 2019 .Dt CCOS 3 .Os .Sh NAME .Nm ccos , .Nm ccosf , +.Nm ccosl , .Nm csin , .Nm csinf .Nm ctan , @@ -43,6 +44,8 @@ .Fn ccos "double complex z" .Ft float complex .Fn ccosf "float complex z" +.Ft long double complex +.Fn ccosl "long double complex z" .Ft double complex .Fn csin "double complex z" .Ft float complex diff --git a/lib/msun/man/ccosh.3 b/lib/msun/man/ccosh.3 index f006442cdc1..502ab2efdf1 100644 --- a/lib/msun/man/ccosh.3 +++ b/lib/msun/man/ccosh.3 @@ -24,12 +24,13 @@ .\" .\" $FreeBSD$ .\" -.Dd October 17, 2011 +.Dd September 2, 2019 .Dt CCOSH 3 .Os .Sh NAME .Nm ccosh , .Nm ccoshf , +.Nm ccoshl , .Nm csinh , .Nm csinhf .Nm ctanh , @@ -43,6 +44,8 @@ .Fn ccosh "double complex z" .Ft float complex .Fn ccoshf "float complex z" +.Ft long double complex +.Fn ccoshl "long double complex z" .Ft double complex .Fn csinh "double complex z" .Ft float complex diff --git a/lib/msun/man/csin.3 b/lib/msun/man/csin.3 new file mode 100644 index 00000000000..180a44135fe --- /dev/null +++ b/lib/msun/man/csin.3 @@ -0,0 +1,76 @@ +.\" $OpenBSD: csin.3,v 1.2 2013/06/05 03:40:26 tedu Exp $ +.\" +.\" Copyright (c) 2011 Martynas Venckus +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 2, 2019 +.Dt CSIN 3 +.Os +.Sh NAME +.Nm csin , +.Nm csinf , +.Nm csinl +.Nd complex circular sine +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn csin "double complex z" +.Ft float complex +.Fn csinf "float complex z" +.Ft long double complex +.Fn csinl "long double complex z" +.Sh DESCRIPTION +The +.Fn csin , +.Fn csinf +and +.Fn csinl +functions compute the complex circular sine of +.Fa z . +.Pp +If +.Fa z += x + iy, then +.Bd -literal -offset indent +csin(z) = sin(x) cosh(y) + i cos(x) sinh(y). +.Ed +.Sh RETURN VALUES +The +.Fn csin , +.Fn csinf +and +.Fn csinl +functions return the complex circular sine of +.Fa z . +.Sh SEE ALSO +.Xr ccos 3 , +.Xr ctan 3 +.Sh STANDARDS +The +.Fn csin , +.Fn csinf +and +.Fn csinl +functions conform to +.St -isoC-99 . +.Sh HISTORY +The +.Fn csin , +.Fn csinf , +and +.Fn csinl +functions first appeared in +.Fx 13. diff --git a/lib/msun/man/csinh.3 b/lib/msun/man/csinh.3 new file mode 100644 index 00000000000..4b8cc991fd7 --- /dev/null +++ b/lib/msun/man/csinh.3 @@ -0,0 +1,74 @@ +.\" $OpenBSD: csinh.3,v 1.2 2013/06/05 03:40:26 tedu Exp $ +.\" +.\" Copyright (c) 2011 Martynas Venckus +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 2, 2019 +.Dt CSINH 3 +.Os +.Sh NAME +.Nm csinh , +.Nm csinhf , +.Nm csinhl +.Nd complex hyperbolic sine +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn csinh "double complex z" +.Ft float complex +.Fn csinhf "float complex z" +.Ft long double complex +.Fn csinhl "long double complex z" +.Sh DESCRIPTION +The +.Fn csinh , +.Fn csinhf +and +.Fn csinhl +functions compute the complex hyperbolic sine of +.Fa z . +.Pp +For all complex floating-point numbers +.Fa z , +.Bd -literal -offset indent +csinh(z) = (cexp(z) - cexp(-z)) / 2. +.Ed +.Sh RETURN VALUES +The +.Fn csinh , +.Fn csinhf +and +.Fn csinhl +functions return the complex hyperbolic sine of +.Fa z . +.Sh SEE ALSO +.Xr ccosh 3 , +.Xr ctanh 3 +.Sh STANDARDS +The +.Fn csinh , +.Fn csinhf +and +.Fn csinhl +functions conform to +.St -isoC-99 . +.Sh HISTORY +The +.Fn csinh , +.Fn csinhf , +.Fn csinhl +functions first appeared in +.Fx 13 . diff --git a/lib/msun/man/ctan.3 b/lib/msun/man/ctan.3 new file mode 100644 index 00000000000..9822e693cc8 --- /dev/null +++ b/lib/msun/man/ctan.3 @@ -0,0 +1,82 @@ +.\" $OpenBSD: ctan.3,v 1.2 2013/06/05 03:40:26 tedu Exp $ +.\" +.\" Copyright (c) 2011 Martynas Venckus +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 2, 2019 +.Dt CTAN 3 +.Os +.Sh NAME +.Nm ctan , +.Nm ctanf , +.Nm ctanl +.Nd complex circular tangent +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn ctan "double complex z" +.Ft float complex +.Fn ctanf "float complex z" +.Ft long double complex +.Fn ctanl "long double complex z" +.Sh DESCRIPTION +The +.Fn ctan , +.Fn ctanf +and +.Fn ctanl +functions compute the complex circular tangent of +.Fa z . +.Pp +If +.Fa z += x + iy, then +.Bd -literal -offset indent +ctan(z) = (sin(2x) + i sinh(2y)) / (cos(2x) + cosh(2y)). +.Ed +.Pp +On the real axis the denominator is zero at odd multiples of Pi/2. +The denominator is evaluated by its Taylor series near these points. +.Bd -literal -offset indent +ctan(z) = -i ctanh(iz). +.Ed +.Sh RETURN VALUES +The +.Fn ctan , +.Fn ctanf +and +.Fn ctanl +functions return the complex circular tangent of +.Fa z . +.Sh SEE ALSO +.Xr ccos 3 , +.Xr csin 3 +.Sh STANDARDS +The +.Fn ctan , +.Fn ctanf +and +.Fn ctanl +functions conform to +.St -isoC-99 . +.Sh HISTORY +The +.Fn ctan , +.Fn ctanf , +and +.Fn ctanl +functions first appeared in +.Fx 13 . diff --git a/lib/msun/man/ctanh.3 b/lib/msun/man/ctanh.3 new file mode 100644 index 00000000000..98f476de184 --- /dev/null +++ b/lib/msun/man/ctanh.3 @@ -0,0 +1,76 @@ +.\" $OpenBSD: ctanh.3,v 1.2 2013/06/05 03:40:26 tedu Exp $ +.\" +.\" Copyright (c) 2011 Martynas Venckus +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 2, 2019 +.Dt CTANH 3 +.Os +.Sh NAME +.Nm ctanh , +.Nm ctanhf , +.Nm ctanhl +.Nd complex hyperbolic tangent +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn ctanh "double complex z" +.Ft float complex +.Fn ctanhf "float complex z" +.Ft long double complex +.Fn ctanhl "long double complex z" +.Sh DESCRIPTION +The +.Fn ctanh , +.Fn ctanhf +and +.Fn ctanhl +functions compute the complex hyperbolic tangent of +.Fa z . +.Pp +If +.Fa z += x + iy, then +.Bd -literal -offset indent +ctanh(z) = (sinh(2x) + i sin(2y)) / (cosh(2x) + cos(2y)). +.Ed +.Sh RETURN VALUES +The +.Fn ctanh , +.Fn ctanhf +and +.Fn ctanhl +functions return the complex hyperbolic tangent of +.Fa z . +.Sh SEE ALSO +.Xr ccosh 3 , +.Xr csinh 3 +.Sh STANDARDS +The +.Fn ctanh , +.Fn ctanhf +and +.Fn ctanhl +functions conform to +.St -isoC-99 . +.Sh HISTORY +The +.Fn ctanh , +.Fn ctanhf , +and +.Fn ctanhl +first appeared in +.Fx 13 . diff --git a/lib/msun/src/s_ccos.c b/lib/msun/src/s_ccos.c new file mode 100644 index 00000000000..aea3f9548e7 --- /dev/null +++ b/lib/msun/src/s_ccos.c @@ -0,0 +1,89 @@ +/* $OpenBSD: s_ccos.c,v 1.7 2016/09/12 19:47:02 guenther Exp $ */ +/* + * Copyright (c) 2008 Stephen L. Moshier + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* ccos() + * + * Complex circular cosine + * + * + * + * SYNOPSIS: + * + * double complex ccos(); + * double complex z, w; + * + * w = ccos (z); + * + * + * + * DESCRIPTION: + * + * If + * z = x + iy, + * + * then + * + * w = cos x cosh y - i sin x sinh y. + * + * + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * DEC -10,+10 8400 4.5e-17 1.3e-17 + * IEEE -10,+10 30000 3.8e-16 1.0e-16 + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +/* calculate cosh and sinh */ + +static 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; + } +} + +/* 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/msun/src/s_ccosf.c b/lib/msun/src/s_ccosf.c new file mode 100644 index 00000000000..4194b9ebb06 --- /dev/null +++ b/lib/msun/src/s_ccosf.c @@ -0,0 +1,88 @@ +/* $OpenBSD: s_ccosf.c,v 1.2 2010/07/18 18:42:26 guenther Exp $ */ +/* + * Copyright (c) 2008 Stephen L. Moshier + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* ccosf() + * + * Complex circular cosine + * + * + * + * SYNOPSIS: + * + * void ccosf(); + * cmplxf z, w; + * + * ccosf( &z, &w ); + * + * + * + * DESCRIPTION: + * + * If + * z = x + iy, + * + * then + * + * w = cos x cosh y - i sin x sinh y. + * + * + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * IEEE -10,+10 30000 1.8e-7 5.5e-8 + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +/* calculate cosh and sinh */ + +static void +_cchshf(float xx, float *c, float *s) +{ + float x, e, ei; + + x = xx; + 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; + } +} + +/* 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/msun/src/s_ccoshl.c b/lib/msun/src/s_ccoshl.c new file mode 100644 index 00000000000..5cd3a8cb528 --- /dev/null +++ b/lib/msun/src/s_ccoshl.c @@ -0,0 +1,62 @@ +/* $OpenBSD: s_ccoshl.c,v 1.2 2011/07/20 19:28:33 martynas Exp $ */ + +/* + * Copyright (c) 2008 Stephen L. Moshier + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* ccoshl + * + * Complex hyperbolic cosine + * + * + * + * SYNOPSIS: + * + * long double complex ccoshl(); + * long double complex z, w; + * + * w = ccoshl (z); + * + * + * + * DESCRIPTION: + * + * ccosh(z) = cosh x cos y + i sinh x sin y . + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * IEEE -10,+10 30000 2.9e-16 8.1e-17 + * + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +long double complex +ccoshl(long double complex z) +{ + long double complex w; + long double x, y; + + x = creall(z); + y = cimagl(z); + w = coshl(x) * cosl(y) + (sinhl(x) * sinl(y)) * I; + return (w); +} diff --git a/lib/msun/src/s_ccosl.c b/lib/msun/src/s_ccosl.c new file mode 100644 index 00000000000..7952362248d --- /dev/null +++ b/lib/msun/src/s_ccosl.c @@ -0,0 +1,85 @@ +/* $OpenBSD: s_ccosl.c,v 1.2 2011/07/20 19:28:33 martynas Exp $ */ + +/* + * Copyright (c) 2008 Stephen L. Moshier + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* ccosl() + * + * Complex circular cosine + * + * + * + * SYNOPSIS: + * + * long double complex ccosl(); + * long double complex z, w; + * + * w = ccosl( z ); + * + * + * + * DESCRIPTION: + * + * If + * z = x + iy, + * + * then + * + * w = cos x cosh y - i sin x sinh y. + * + * + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * DEC -10,+10 8400 4.5e-17 1.3e-17 + * IEEE -10,+10 30000 3.8e-16 1.0e-16 + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +static void +cchshl(long double x, long double *c, long double *s) +{ + long double e, ei; + + if(fabsl(x) <= 0.5L) { + *c = coshl(x); + *s = sinhl(x); + } else { + e = expl(x); + ei = 0.5L/e; + e = 0.5L * e; + *s = e - ei; + *c = e + ei; + } +} + +long double complex +ccosl(long double complex z) +{ + long double complex w; + long double ch, sh; + + cchshl(cimagl(z), &ch, &sh); + w = cosl(creall(z)) * ch + (-sinl(creall(z)) * sh) * I; + return (w); +} diff --git a/lib/msun/src/s_csinhl.c b/lib/msun/src/s_csinhl.c new file mode 100644 index 00000000000..9dc1bcb8020 --- /dev/null +++ b/lib/msun/src/s_csinhl.c @@ -0,0 +1,61 @@ +/* $OpenBSD: s_csinhl.c,v 1.2 2011/07/20 19:28:33 martynas Exp $ */ + +/* + * Copyright (c) 2008 Stephen L. Moshier + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* csinhl + * + * Complex hyperbolic sine + * + * + * + * SYNOPSIS: + * + * long double complex csinhl(); + * long double complex z, w; + * + * w = csinhl (z); + * + * DESCRIPTION: + * + * csinh z = (cexp(z) - cexp(-z))/2 + * = sinh x * cos y + i cosh x * sin y . + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * IEEE -10,+10 30000 3.1e-16 8.2e-17 + * + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +long double complex +csinhl(long double complex z) +{ + long double complex w; + long double x, y; + + x = creall(z); + y = cimagl(z); + w = sinhl(x) * cosl(y) + (coshl(x) * sinl(y)) * I; + return (w); +} diff --git a/lib/msun/src/s_csinl.c b/lib/msun/src/s_csinl.c new file mode 100644 index 00000000000..1a1ea16f64e --- /dev/null +++ b/lib/msun/src/s_csinl.c @@ -0,0 +1,87 @@ +/* $OpenBSD: s_csinl.c,v 1.2 2011/07/20 19:28:33 martynas Exp $ */ + +/* + * Copyright (c) 2008 Stephen L. Moshier + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* csinl() + * + * Complex circular sine + * + * + * + * SYNOPSIS: + * + * long double complex csinl(); + * long double complex z, w; + * + * w = csinl( z ); + * + * + * + * DESCRIPTION: + * + * If + * z = x + iy, + * + * then + * + * w = sin x cosh y + i cos x sinh y. + * + * + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * DEC -10,+10 8400 5.3e-17 1.3e-17 + * IEEE -10,+10 30000 3.8e-16 1.0e-16 + * Also tested by csin(casin(z)) = z. + * + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +static void +cchshl(long double x, long double *c, long double *s) +{ + long double e, ei; + + if(fabsl(x) <= 0.5L) { + *c = coshl(x); + *s = sinhl(x); + } else { + e = expl(x); + ei = 0.5L/e; + e = 0.5L * e; + *s = e - ei; + *c = e + ei; + } +} + +long double complex +csinl(long double complex z) +{ + long double complex w; + long double ch, sh; + + cchshl(cimagl(z), &ch, &sh); + w = sinl(creall(z)) * ch + (cosl(creall(z)) * sh) * I; + return (w); +} diff --git a/lib/msun/src/s_ctanhl.c b/lib/msun/src/s_ctanhl.c new file mode 100644 index 00000000000..c144a30c05b --- /dev/null +++ b/lib/msun/src/s_ctanhl.c @@ -0,0 +1,63 @@ +/* $OpenBSD: s_ctanhl.c,v 1.2 2011/07/20 19:28:33 martynas Exp $ */ + +/* + * Copyright (c) 2008 Stephen L. Moshier + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* ctanhl + * + * Complex hyperbolic tangent + * + * + * + * SYNOPSIS: + * + * long double complex ctanhl(); + * long double complex z, w; + * + * w = ctanhl (z); + * + * + * + * DESCRIPTION: + * + * tanh z = (sinh 2x + i sin 2y) / (cosh 2x + cos 2y) . + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * IEEE -10,+10 30000 1.7e-14 2.4e-16 + * + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +long double complex +ctanhl(long double complex z) +{ + long double complex w; + long double x, y, d; + + x = creall(z); + y = cimagl(z); + d = coshl(2.0L * x) + cosl(2.0L * y); + w = sinhl(2.0L * x) / d + (sinl(2.0L * y) / d) * I; + return (w); +} diff --git a/lib/msun/src/s_ctanl.c b/lib/msun/src/s_ctanl.c new file mode 100644 index 00000000000..3f8a949487a --- /dev/null +++ b/lib/msun/src/s_ctanl.c @@ -0,0 +1,160 @@ +/* $OpenBSD: s_ctanl.c,v 1.3 2011/07/20 21:02:51 martynas Exp $ */ + +/* + * Copyright (c) 2008 Stephen L. Moshier + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* ctanl() + * + * Complex circular tangent + * + * + * + * SYNOPSIS: + * + * long double complex ctanl(); + * long double complex z, w; + * + * w = ctanl( z ); + * + * + * + * DESCRIPTION: + * + * If + * z = x + iy, + * + * then + * + * sin 2x + i sinh 2y + * w = --------------------. + * cos 2x + cosh 2y + * + * On the real axis the denominator is zero at odd multiples + * of PI/2. The denominator is evaluated by its Taylor + * series near these points. + * + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * DEC -10,+10 5200 7.1e-17 1.6e-17 + * IEEE -10,+10 30000 7.2e-16 1.2e-16 + * Also tested by ctan * ccot = 1 and catan(ctan(z)) = z. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#if LDBL_MANT_DIG == 64 +static const long double MACHEPL= 5.42101086242752217003726400434970855712890625E-20L; +#elif LDBL_MANT_DIG == 113 +static const long double MACHEPL = 9.629649721936179265279889712924636592690508e-35L; +#endif + +static const long double PIL = 3.141592653589793238462643383279502884197169L; +static const long double DP1 = 3.14159265358979323829596852490908531763125L; +static const long double DP2 = 1.6667485837041756656403424829301998703007e-19L; +static const long double DP3 = 1.8830410776607851167459095484560349402753e-39L; + +static long double +redupil(long double x) +{ + long double t; + long i; + + t = x / PIL; + if (t >= 0.0L) + t += 0.5L; + else + t -= 0.5L; + + i = t; /* the multiple */ + t = i; + t = ((x - t * DP1) - t * DP2) - t * DP3; + return (t); +} + +static long double +ctansl(long double complex z) +{ + long double f, x, x2, y, y2, rn, t; + long double d; + + x = fabsl(2.0L * creall(z)); + y = fabsl(2.0L * cimagl(z)); + + x = redupil(x); + + x = x * x; + y = y * y; + x2 = 1.0L; + y2 = 1.0L; + f = 1.0L; + rn = 0.0L; + d = 0.0L; + do { + rn += 1.0L; + f *= rn; + rn += 1.0L; + f *= rn; + x2 *= x; + y2 *= y; + t = y2 + x2; + t /= f; + d += t; + + rn += 1.0L; + f *= rn; + rn += 1.0L; + f *= rn; + x2 *= x; + y2 *= y; + t = y2 - x2; + t /= f; + d += t; + } + while (fabsl(t/d) > MACHEPL); + return(d); +} + +long double complex +ctanl(long double complex z) +{ + long double complex w; + long double d, x, y; + + x = creall(z); + y = cimagl(z); + d = cosl(2.0L * x) + coshl(2.0L * y); + + if (fabsl(d) < 0.25L) { + d = fabsl(d); + d = ctansl(z); + } + if (d == 0.0L) { + /*mtherr( "ctan", OVERFLOW );*/ + w = LDBL_MAX + LDBL_MAX * I; + return (w); + } + + w = sinl(2.0L * x) / d + (sinhl(2.0L * y) / d) * I; + return (w); +} -- 2.23.0