Implementation of half-cycle trignometric functions
Steve Kargl
sgk at troutmask.apl.washington.edu
Fri Apr 28 17:05:29 UTC 2017
On Fri, Apr 28, 2017 at 06:00:19PM +1000, Bruce Evans wrote:
>
> On Thu, 27 Apr 2017, Steve Kargl wrote:
>
> > I have attached a new diff to the bugzilla report. The
> > diff is 3090 lines and won't be broadcast the mailing list.
>
> But no one will see it there.
>
Here's the diff in its full glory (without the sloppy
threshold fix). There no signature at the end.
Index: lib/msun/Makefile
===================================================================
--- lib/msun/Makefile (revision 317529)
+++ lib/msun/Makefile (working copy)
@@ -59,6 +59,7 @@
s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_carg.c s_cargf.c s_cargl.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_cospi.c s_cospif.c \
s_csqrt.c s_csqrtf.c s_erf.c s_erff.c \
s_exp2.c s_exp2f.c s_expm1.c s_expm1f.c s_fabsf.c s_fdim.c \
s_finite.c s_finitef.c \
@@ -74,7 +75,10 @@
s_rint.c s_rintf.c s_round.c s_roundf.c \
s_scalbln.c s_scalbn.c s_scalbnf.c s_signbit.c \
s_signgam.c s_significand.c s_significandf.c s_sin.c s_sinf.c \
- s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_tgammaf.c s_trunc.c s_truncf.c \
+ s_sinpi.c s_sinpif.c \
+ s_tan.c s_tanf.c s_tanh.c s_tanhf.c \
+ s_tanpi.c s_tanpif.c \
+ s_tgammaf.c s_trunc.c s_truncf.c \
w_cabs.c w_cabsf.c w_drem.c w_dremf.c
# Location of fpmath.h and _fpmath.h
@@ -100,11 +104,16 @@
e_lgammal.c e_lgammal_r.c \
e_remainderl.c e_sinhl.c e_sqrtl.c \
invtrig.c k_cosl.c k_sinl.c k_tanl.c \
- s_asinhl.c s_atanl.c s_cbrtl.c s_ceill.c s_cosl.c s_cprojl.c \
+ s_asinhl.c s_atanl.c s_cbrtl.c s_ceill.c s_cosl.c \
+ s_cospil.c \
+ s_cprojl.c \
s_csqrtl.c s_erfl.c s_exp2l.c s_expl.c s_floorl.c s_fmal.c \
s_fmaxl.c s_fminl.c s_frexpl.c s_logbl.c s_logl.c s_nanl.c \
s_nextafterl.c s_nexttoward.c s_remquol.c s_rintl.c s_roundl.c \
- s_scalbnl.c s_sinl.c s_tanhl.c s_tanl.c s_truncl.c w_cabsl.c
+ s_scalbnl.c s_sinl.c \
+ s_sinpil.c \
+ s_tanhl.c s_tanl.c \
+ s_tanpil.c s_truncl.c w_cabsl.c
.endif
# C99 complex functions
@@ -131,13 +140,19 @@
MAN= acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 \
ceil.3 cacos.3 ccos.3 ccosh.3 cexp.3 \
- cimag.3 copysign.3 cos.3 cosh.3 csqrt.3 erf.3 exp.3 fabs.3 fdim.3 \
+ cimag.3 copysign.3 cos.3 cosh.3 \
+ cospi.3 \
+ csqrt.3 erf.3 exp.3 fabs.3 fdim.3 \
feclearexcept.3 feenableexcept.3 fegetenv.3 \
fegetround.3 fenv.3 floor.3 \
fma.3 fmax.3 fmod.3 hypot.3 ieee.3 ieee_test.3 ilogb.3 j0.3 \
lgamma.3 log.3 lrint.3 lround.3 math.3 nan.3 \
nextafter.3 remainder.3 rint.3 \
- round.3 scalbn.3 signbit.3 sin.3 sinh.3 sqrt.3 tan.3 tanh.3 trunc.3 \
+ round.3 scalbn.3 signbit.3 sin.3 sinh.3 \
+ sinpi.3 \
+ sqrt.3 tan.3 tanh.3 \
+ tanpi.3 \
+ trunc.3 \
complex.3
MLINKS+=acos.3 acosf.3 acos.3 acosl.3
@@ -166,6 +181,7 @@
MLINKS+=copysign.3 copysignf.3 copysign.3 copysignl.3
MLINKS+=cos.3 cosf.3 cos.3 cosl.3
MLINKS+=cosh.3 coshf.3 cosh.3 coshl.3
+MLINKS+=cospi.3 cospif.3 cospi.3 cospil.3
MLINKS+=csqrt.3 csqrtf.3 csqrt.3 csqrtl.3
MLINKS+=erf.3 erfc.3 erf.3 erff.3 erf.3 erfcf.3 erf.3 erfl.3 erf.3 erfcl.3
MLINKS+=exp.3 expm1.3 exp.3 expm1f.3 exp.3 expm1l.3 exp.3 pow.3 exp.3 powf.3 \
@@ -216,10 +232,12 @@
MLINKS+=scalbn.3 scalbnf.3 scalbn.3 scalbnl.3
MLINKS+=sin.3 sinf.3 sin.3 sinl.3
MLINKS+=sinh.3 sinhf.3 sinh.3 sinhl.3
+MLINKS+=sinpi.3 sinpif.3 sinpi.3 sinpil.3
MLINKS+=sqrt.3 cbrt.3 sqrt.3 cbrtf.3 sqrt.3 cbrtl.3 sqrt.3 sqrtf.3 \
sqrt.3 sqrtl.3
MLINKS+=tan.3 tanf.3 tan.3 tanl.3
MLINKS+=tanh.3 tanhf.3 tanh.3 tanhl.3
+MLINKS+=tanpi.3 tanpif.3 tanpi.3 tanpil.3
MLINKS+=trunc.3 truncf.3 trunc.3 truncl.3
.include <src.opts.mk>
Index: lib/msun/Symbol.map
===================================================================
--- lib/msun/Symbol.map (revision 317529)
+++ lib/msun/Symbol.map (working copy)
@@ -294,4 +294,13 @@
casinl;
catanl;
catanhl;
+ cospi;
+ cospif;
+ cospil;
+ sinpi;
+ sinpif;
+ sinpil;
+ tanpi;
+ tanpif;
+ tanpil;
};
Index: lib/msun/ld128/k_cospil.c
===================================================================
--- lib/msun/ld128/k_cospil.c (nonexistent)
+++ lib/msun/ld128/k_cospil.c (working copy)
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/k_cospi.c for implementation details.
+ *
+ * FIXME: This has not been compiled nor has it been tested for accuracy.
+ * FIXME: This should use bit twiddling.
+ */
+
+static const long double
+c0 = 1,
+c1hi = -4.93480220054467930941724549993807541e+00L,
+c1lo = -1.61159244006703024615160135944400084e-34L,
+c02 = 4.05871212641676821818501386202937963e+00L,
+c03 = -1.33526276885458949587530478285057448e+00L,
+c04 = 2.35330630358893204541879352772399571e-01L,
+c05 = -2.58068913900140600125982936922503890e-02L,
+c06 = 1.92957430940392304790328456072058283e-03L,
+c07 = -1.04638104924845707113757250204498056e-04L,
+c08 = 4.30306958703294680806457740580669010e-06L,
+c09 = -1.38789524622131344829253970500107607e-07L,
+c10 = 3.60473079732244660718578413933676910e-09L,
+c11 = -7.70070692297072534641720608808474790e-11L,
+c12 = 1.37684487309360112303144478033041762e-12L,
+c13 = -2.07957304470476734518573046614539573e-14L;
+
+static inline long double
+__kernel_cospi(long double x)
+{
+ union IEEEl2bits u;
+ long double c, chi, clo, x2, x2lo;
+ double x2hi;
+
+ x2 = x * x;
+
+ c = c09 + (c10 + (c11 + (c12 + c13 * x2) * x2) * x2) * x2;
+ c = c05 + (c06 + (c07 + (c08 + c * x2) * x2) * x2) * x2;
+ c = (c02 + (c03 + (c04 + c * x2) * x2) * x2) * x2 + c1hi;
+
+ if (x2 < 0x1p-6) /* |x| < 0x1p-6 */
+ return (c0 + c * x2);
+
+ x2hi = x2;
+ x2lo = x2 - x2hi;
+
+ c = clo * x2lo + chi * x2lo + clo * x2hi + (chi * x2hi + c0);
+
+ return (c);
+}
Property changes on: lib/msun/ld128/k_cospil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/ld128/k_sinpil.c
===================================================================
--- lib/msun/ld128/k_sinpil.c (nonexistent)
+++ lib/msun/ld128/k_sinpil.c (working copy)
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/k_sinpi.c for implementation details.
+ *
+ * FIXME: This has not been compiled nor has it been tested for accuracy.
+ * FIXME: This should use bit twiddling.
+ *
+ * Compute sinpi(x) = sin(pi*x) in the interval [0,0.25]
+ */
+
+static const long double
+s0lo = 3.14159265358979322702026593105983920e+00L,
+s0md = 1.14423774522196636802274144823600323e-17L,
+s0lo = -5.10459839933399352423791604618557491e-52L,
+s01 = -5.16771278004997002924605251118356578e+00L,
+s02 = 2.55016403987734544385617758369521912e+00L,
+s03 = -5.99264529320792076887739383518724498e-01L,
+s04 = 8.21458866111282287988023605285125252e-02L,
+s05 = -7.37043094571435077725854643888422319e-03L,
+s06 = 4.66302805767612564382677987452304496e-04L,
+s07 = -2.19153534478302140522509092972929589e-05L,
+s08 = 7.95205400147494466063630770553231865e-07L,
+s09 = -2.29484289960219849488354905723109270e-08L,
+s10 = 5.39266447760508581521426149354268607e-10L,
+s11 = -1.05182947998557665557194979309998767e-11L,
+s12 = 1.72036427603492093074818577722479034e-13L;
+
+static inline long double
+__kernel_sinpi(long double x)
+{
+ union IEEEl2bits u;
+ long double hi, lo, sm, x2, xlo;
+ double xhi;
+
+ /* Split x into high and low parts. */
+ xhi = x;
+ xlo = x - xhi;
+
+ x2 = x * x;
+ sm = x2 * (x2 * (x2 * (x2 * s12 + s11) + s10) + s09) + s08;
+ sm = x2 * (x2 * (x2 * (x2 * sm + s07) + s06) + s05) + s04;
+ sm = x2 * (x2 * (x2 * sm + s03) + s02) + s01;
+ lo = xlo * (x + xhi) * sm;
+ hi = sm * xhi * xhi;
+ lo = x * (lo + s0lo) + xlo * (s0hi + s0md) + x * hi;
+
+ return (lo + xhi * s0md + xhi * s0hi);
+}
Property changes on: lib/msun/ld128/k_sinpil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/ld128/s_cospil.c
===================================================================
--- lib/msun/ld128/s_cospil.c (nonexistent)
+++ lib/msun/ld128/s_cospil.c (working copy)
@@ -0,0 +1,98 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/s_cospi.c for implementation details.
+ *
+ * FIXME: This has not been compiled nor has it been tested for accuracy.
+ * FIXME: This should use bit twiddling.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_cospi.c"
+#include "k_sinpi.c"
+
+static inline long double
+__compute_cospil(long double x)
+{
+
+ if (x < 0.5) {
+ if (x < 0.25)
+ return (__kernel_cospil(x));
+ return (__kernel_sinpil(0.5 - x));
+ } else {
+ if (x < 0.75)
+ return (-__kernel_sinpil(x - 0.5));
+ return (-__kernel_cospil(1 - x));
+ }
+}
+
+long double
+cospil(long double x)
+{
+ const double huge = 1e+300;
+ long double ax, xf;
+ uint32_t ix;
+
+ ax = fabsl(x);
+
+ if (ax < 1) { /* |x| < 1 */
+ if (ax < 0x1p-60) { /* |x| < 0x1p-60 */
+ if (huge + x > 0)
+ return (1);
+ }
+ if (ax == 0.5)
+ return (0);
+ return (__compute_cospil(ax));
+ }
+
+ if (ax < 0x1p112) { /* 1 <= |x| < 0x1p112 */
+
+ xf = floorl(ax);
+
+ ax -= x;
+ if (ax == 0.5)
+ return (0);
+
+ ax = ax == 0 ? 1 : __compute_cospil(ax);
+
+ if (xf > 0x1p50) xf -= 0x1p50;
+ if (xf > 0x1p30) xf -= 0x1p30;
+ ix = (uint32_t)xf;
+
+ return (ix & 1 ? -ax : ax);
+ }
+
+ if (isinf(x) || isnan(x))
+ return (x - x);
+
+ /*
+ * |x| >= 0x1p112 is always an even integer, so return 1.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID.
+ */
+ return (1);
+}
Property changes on: lib/msun/ld128/s_cospil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/ld128/s_sinpil.c
===================================================================
--- lib/msun/ld128/s_sinpil.c (nonexistent)
+++ lib/msun/ld128/s_sinpil.c (working copy)
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/s_sinpi.c for implementation details.
+ *
+ * FIXME: This has not been compiled nor has it been tested for accuracy.
+ * FIXME: This should use bit twiddling.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_cospil.c"
+#include "k_sinpil.c"
+
+static const long double pihi = 3.14159265358979322702026593105983920e+00L;
+static const long double pilo = 1.14423774522196636802434264184180742e-17L;
+
+static inline long double
+__compute_sinpil(long double x)
+{
+
+ if (x < 0.5) {
+ if (x <= 0.25)
+ return (__kernel_sinpil(x));
+ return (__kernel_cospil(0.5 - x));
+ } else {
+ if (x < 0.75)
+ return (__kernel_cospil(x - 0.5));
+ return (__kernel_sinpil(1 - x));
+ }
+}
+
+long double
+sinpi(long double x)
+{
+ long double ax, xf;
+ uint32_t ix;
+
+ ax = fabsl(x);
+
+ if (ax < 1) { /* |x| < 1 */
+ if (ax < 0x1p-60) { /* |x| < 0x1p-60 */
+ if (x == 0)
+ return (x);
+ return (pilo * x + pihi * x);
+ }
+ ax = __compute_sinpil(ax);
+ return (copysignl(ax, x));
+ }
+
+ if (ax < 0x1p112) { /* 1 <= |x| < 0x1p112 */
+
+ xf = floorl(ax);
+
+ ax -= xf;
+ if (ax == 0) {
+ ax = 0;
+ } else {
+ ax = __compute_sinpil(ax);
+ if (xf > 0x1p50) xf -= 0x1p50;
+ if (xf > 0x1p30) xf -= 0x1p30;
+ ix = (uint32_t)xf;
+ if (ix & 1) ax = -ax;
+ }
+ return (copysignl(ax, x));
+ }
+
+ if (isinf(x) || isnan(x))
+ return (x - x);
+
+ /*
+ * |x| >= 0x1p112 is always an integer, so return +-0.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID.
+ */
+ return (copysignl(0, x));
+}
Property changes on: lib/msun/ld128/s_sinpil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/ld128/s_tanpil.c
===================================================================
--- lib/msun/ld128/s_tanpil.c (nonexistent)
+++ lib/msun/ld128/s_tanpil.c (working copy)
@@ -0,0 +1,98 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/s_tanpi.c for implementation details.
+ *
+ * FIXME: This has not been compiled nor has it been tested for accuracy.
+ * FIXME: This should use bit twiddling.
+ * FIXME: This should use a polynomial approximation in [0,0.25], but the
+ * FIXME: increase in max ULP is probably small, so who cares.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const long double pihi = 3.14159265358979322702026593105983920e+00L;
+static const long double pilo = 1.14423774522196636802434264184180742e-17L;
+
+static inline long double
+__k_tanpi(long double x)
+{
+
+ return (sinpil(x) / cospil(x));
+}
+
+static inline long double
+__compute_tanpi(long double x)
+{
+
+ return (x < 0.5 ? __k_tanpil(x) : -__k_tanpil(1 - x));
+}
+
+long double
+tanpil(long double x)
+{
+ long double ax, xf;
+ uint32_t ix;
+
+ ax = fabsl(ax);
+
+ if (ax < 1) { /* |x| < 1 */
+ if (ax < 0x1p-60) { /* |x| < 0x1p-60 */
+ if (x == 0)
+ return (x);
+ return (pilo * x + pihi * x);
+ }
+ if (ax == 0.5)
+ return ((x - x) / (x - x));
+ ax = __compute_tanpil(ax);
+ return (copysignl(ax, x));
+ }
+
+ if (ix < 0x1p112) { /* 1 <= |x| < 0x1p112 */
+
+ xf = floorl(ax);
+
+ ax -= xf;
+
+ if (ax == 0.5)
+ return ((x - x) / (x - x));
+
+ ax = ax == 0 ? 0 : __compute_tanpil(ax);
+ return (copysignl(ax, x));
+ }
+
+ /* x = +-inf or nan. */
+ if (isinf(x) || isnan(x))
+ return (x - x);
+
+ /*
+ * |x| >= 0x1p53 is always an integer, so return +-0.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID.
+ */
+ return (copysignl(0, x));
+}
Property changes on: lib/msun/ld128/s_tanpil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/ld80/k_cospil.c
===================================================================
--- lib/msun/ld80/k_cospil.c (nonexistent)
+++ lib/msun/ld80/k_cospil.c (working copy)
@@ -0,0 +1,78 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/k_cospi.c for implementation details.
+ */
+
+static const union IEEEl2bits
+c1hiu = LD80C(0x9de9e64df22ef2d2, 2, -4.93480220054467930927e+00L),
+c1lou = LD80C(0xadc4baf0dd791c3e, -63, -1.47187625629472133798e-19L),
+c2u = LD80C(0x81e0f840dad61d9b, 2, 4.05871212641676821836e+00L);
+#define c1hi (c1hiu.e)
+#define c1lo (c1lou.e)
+#define c2 (c2u.e)
+
+static const double
+c3 = -1.3352627688545895e+00, /* 0xbff55d3c, 0x7e3cbffa */
+c4 = 2.3533063035889312e-01, /* 0x3fce1f50, 0x6891bab8 */
+c5 = -2.5806891390008115e-02, /* 0xbf9a6d1f, 0x2a2043da */
+c6 = 1.9295743091289794e-03, /* 0x3f5f9d38, 0xa362e3d1 */
+c7 = -1.0463809745687055e-04, /* 0xbf1b6e24, 0xd372e145 */
+c8 = 4.3029513401606985e-06, /* 0x3ed20c42, 0x4210907c */
+c9 = -1.3777927680211844e-07; /* 0xbe827e0f, 0x55d52bbb */
+
+static const double c0 = 1;
+
+static inline long double
+__kernel_cospil(long double x)
+{
+ long double c, chi, clo, x2hi, x2lo;
+
+#if HORNER
+ /* Horner's method. */
+ long double x2;
+ x2 = x * x;
+ c = (c2 + (c3 + (c4 + (c5 + (c6 + (c7 + (c8 + c9 * x2) * x2)
+ * x2) * x2) * x2) * x2) * x2) * x2 + c1hi;
+#else
+ /* Sort of Estrin's method. */
+ long double x2, x4;
+ x2 = x * x;
+ x4 = x2 * x2;
+ c = ((c9 * x2 + c8) * x4 + (c7 * x2 + c6)) * x2 * x4 * x4
+ + ((c5 * x2 + c4) * x4 + (c3 * x2 + c2)) * x2 + c1hi;
+#endif
+ if (x2 < 0x1p-6)
+ return (c0 + c * x2);
+ x2hi =(float)x2;
+ x2lo = x2 - x2hi;
+ chi = (float)c;
+ clo = c - chi + c1lo;
+ c = clo * x2lo + chi * x2lo + clo * x2hi + (chi * x2hi + c0);
+
+ return (c);
+}
Property changes on: lib/msun/ld80/k_cospil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/ld80/k_sinpil.c
===================================================================
--- lib/msun/ld80/k_sinpil.c (nonexistent)
+++ lib/msun/ld80/k_sinpil.c (working copy)
@@ -0,0 +1,78 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/k_sinpi.c for implementation details.
+ */
+
+static const union IEEEl2bits
+s0hiu = LD80C(0xc90fdaa200000000, 1, 3.14159265346825122833e+00L),
+s0lou = LD80C(0x85a308d313167b73, -33, 1.21542010130121322891e-10L),
+s1u = LD80C(0xa55de7312df295f5, 2, -5.16771278004997002909e+00L),
+s2u = LD80C(0xa335e33bad570e85, 1, 2.55016403987734544098e+00L);
+
+#define s0hi (s0hiu.e)
+#define s0lo (s0lou.e)
+#define s1 (s1u.e)
+#define s2 (s2u.e)
+
+static const double
+s3 = -5.9926452932079166e-01, /* 0xbfe32d2c 0xce62bd82 */
+s4 = 8.2145886611090388e-02, /* 0x3fb50783 0x487edcdb */
+s5 = -7.3704309439650085e-03, /* 0xbf7e3074 0xfdc9c0c9 */
+s6 = 4.6630275825043123e-04, /* 0x3f3e8f43 0x18c2a7a0 */
+s7 = -2.1914601021339888e-05, /* 0xbef6faa7 0xea41adee */
+s8 = 7.8877623841310396e-07; /* 0x3eaa7789 0x4aacabad */
+
+static inline long double
+__kernel_sinpil(long double x)
+{
+ long double hi, lo, sm, xhi, xlo;
+ uint64_t lx;
+ uint16_t ix;
+
+#if HORNER
+ /* Horner's method. */
+ long double x2;
+ x2 = x * x;
+ sm = x2 * (x2 * (x2 * (x2 * (x2 * (x2 * (x2 * s8 + s7) + s6)
+ + s5) + s4) + s3) + s2) + s1;
+#else
+ /* Sort of Estrin's method. */
+ long double a, b, x2, x4;
+ x2 = x * x;
+ x4 = x2 * x2;
+ sm = ((x2 * s8 + s7) * x4 + (x2 * s6 + s5)) * (x4 * x4)
+ + (x2 * s4 + s3) * x4 + x2 * s2 + s1;
+#endif
+ xhi = (float)x;
+ xlo = x - xhi;
+ lo = xlo * (x + xhi) * sm;
+ hi = xhi * xhi * sm;
+ lo = x * lo + xlo * (s0hi + s0lo) + x * hi;
+
+ return (lo + xhi * s0lo + xhi * s0hi);
+}
Property changes on: lib/msun/ld80/k_sinpil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/ld80/s_cospil.c
===================================================================
--- lib/msun/ld80/s_cospil.c (nonexistent)
+++ lib/msun/ld80/s_cospil.c (working copy)
@@ -0,0 +1,118 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/s_cospi.c for implementation details.
+ */
+
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+#include <stdint.h>
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+#include "k_cospil.c"
+#include "k_sinpil.c"
+
+static inline long double
+__compute_cospil(long double x)
+{
+
+ if (x < 0.5) {
+ if (x < 0.25)
+ return (__kernel_cospil(x));
+ return (__kernel_sinpil(0.5 - x));
+ } else {
+ if (x < 0.75)
+ return (-__kernel_sinpil(x - 0.5));
+ return (-__kernel_cospil(1 - x));
+ }
+}
+
+long double
+cospil(long double x)
+{
+ volatile static const double vzero = 0;
+ const double huge = 1e+300;
+ long double ax;
+ uint32_t j0;
+ uint64_t lx;
+ uint16_t hx, ix;
+
+ EXTRACT_LDBL80_WORDS(hx, lx, x);
+ ix = hx & 0x7fff;
+ INSERT_LDBL80_WORDS(ax, ix, lx);
+
+ ENTERI();
+
+ if (ix < 0x3fff) { /* |x| < 1 */
+ if (ix < 0x3fdd) { /* |x| < 0x1p-34 */
+ if (huge + x > 0)
+ RETURNI(1);
+ }
+ if (ix == 0x3ffe && lx == 0x8000000000000000ull)
+ RETURNI(0);
+ RETURNI(__compute_cospil(ax));
+ }
+
+ if (ix < 0x403e) { /* 1 <= |x| < 0x1p63 */
+ /* Determine integer part of ax. */
+ j0 = ix - 0x3fff + 1;
+ if (j0 < 32) {
+ lx = (lx >> 32) << 32;
+ lx &= ~(((lx << 32)-1) >> j0);
+ } else {
+ uint64_t m = (uint64_t)-1 >> (j0 + 1);
+ if (lx & m) lx &= ~m;
+ }
+ INSERT_LDBL80_WORDS(x, ix, lx);
+
+ ax -= x;
+ if (ax == 0.5)
+ RETURNI(0);
+
+ ax = ax == 0 ? 1 : __compute_cospil(ax);
+
+ if (j0 > 40) x -= 0x1p40;
+ if (j0 > 30) x -= 0x1p30;
+ j0 = (uint32_t)x;
+
+ return (j0 & 1 ? -ax : ax);
+ }
+
+ if (ix >= 0x7fff)
+ RETURNI(vzero / vzero);
+
+ /*
+ * |x| >= 0x1p63 is always an even integer, so return 1.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID.
+ */
+ if (ax + 1 > 1)
+ ax = 1;
+ return (ax);
+}
Property changes on: lib/msun/ld80/s_cospil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/ld80/s_sinpil.c
===================================================================
--- lib/msun/ld80/s_sinpil.c (nonexistent)
+++ lib/msun/ld80/s_sinpil.c (working copy)
@@ -0,0 +1,123 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/s_sinpi.c for implementation details.
+ */
+
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+#include <stdint.h>
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+#include "k_cospil.c"
+#include "k_sinpil.c"
+
+static inline long double
+__compute_sinpil(long double x)
+{
+
+ if (x <= 0.5) {
+ if (x <= 0.25)
+ return (__kernel_sinpil(x));
+ return (__kernel_cospil(0.5 - x));
+ } else {
+ if (x <= 0.75)
+ return (__kernel_cospil(x - 0.5));
+ return (__kernel_sinpil(1 - x));
+ }
+}
+
+static const double pihi = 3.1415926814079285e+00; /* 0x400921fb 0x58000000 */
+static const double pilo =-2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */
+
+long double
+sinpil(long double x)
+{
+ volatile static const double vzero = 0;
+ long double ax;
+ uint32_t j0;
+ uint64_t lx;
+ uint16_t hx, ix;
+
+ EXTRACT_LDBL80_WORDS(hx, lx, x);
+ ix = hx & 0x7fff;
+ INSERT_LDBL80_WORDS(ax, ix, lx);
+
+ ENTERI();
+
+ if (ix < 0x3fff) { /* |x| < 1 */
+ if (ix < 0x3fdc) { /* |x| < 0x1p-35 */
+ if (x == 0)
+ RETURNI(x);
+ INSERT_LDBL80_WORDS(ax, hx, (lx >> 32) << 32);
+ x -= ax;
+ RETURNI(pilo * x + pihi * x + pilo * ax + pihi * ax);
+ }
+ ax = __compute_sinpil(ax);
+ RETURNI((hx & 0x8000) ? -ax : ax);
+ }
+
+ if (ix < 0x403e) { /* 1 <= |x| < 0x1p63 */
+ /* Determine integer part of ax. */
+ j0 = ix - 0x3fff + 1;
+ if (j0 < 32) {
+ lx = (lx >> 32) << 32;
+ lx &= ~(((lx << 32)-1) >> j0);
+ } else {
+ uint64_t m = (uint64_t)-1 >> (j0 + 1);
+ if (lx & m) lx &= ~m;
+ }
+ INSERT_LDBL80_WORDS(x, ix, lx);
+
+ ax -= x;
+ if (ax == 0) {
+ ax = 0;
+ } else {
+ ax = __compute_sinpil(ax);
+ if (j0 > 40) x -= 0x1p40;
+ if (j0 > 30) x -= 0x1p30;
+ j0 = (uint32_t)x;
+ if (j0 & 1) ax = -ax;
+ }
+ RETURNI((hx & 0x8000) ? -ax : ax);
+ }
+
+ /* x = +-inf or nan. */
+ if (ix >= 0x7fff)
+ RETURNI(vzero / vzero);
+
+ /*
+ * |x| >= 0x1p63 is always an integer, so return +-0.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID.
+ */
+ if (ax + 1 > 1)
+ ax = copysignl(0, x);
+ RETURNI(ax);
+}
Property changes on: lib/msun/ld80/s_sinpil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/ld80/s_tanpil.c
===================================================================
--- lib/msun/ld80/s_tanpil.c (nonexistent)
+++ lib/msun/ld80/s_tanpil.c (working copy)
@@ -0,0 +1,195 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/s_tanpi.c for implementation details.
+ */
+
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+#include <stdint.h>
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+#include "k_cospil.c"
+#include "k_sinpil.c"
+
+static const double pihi = 3.1415926814079285e+00; /* 0x400921fb 0x58000000 */
+static const double pilo =-2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */
+
+static const union IEEEl2bits
+t00hiu = LD80C(0xc90fdaa22168c235, 1, 3.14159265358979323851e+00L),
+t00lou = LD80C(0xecdfa9e9520ede79, -65, -5.01599541779735313611e-20L),
+t01hiu = LD80C(0xa55de7312df295f5, 3, 1.03354255600999400582e+01L),
+t01lou = LD80C(0x8d51cc1ca8412de2, -62, 2.39404580332694307957e-19L),
+t02hiu = LD80C(0xa335e33bad570ec7, 5, 4.08026246380375272847e+01L),
+t02lou = LD80C(0xe72db1e59703a7ba, -60, -1.56652642070969805771e-18L),
+t03u = LD80C(0xa2fffcda474ac1d3, 7, 1.62999951975255277944e+02L),
+t04u = LD80C(0xa2fa3971d7988829, 9, 6.51909756145994949750e+02L),
+t05u = LD80C(0xa2f99792aec80f33, 11, 2.60759950512193695427e+03L),
+t06u = LD80C(0xa2f985abafb74d99, 13, 1.04303805377441052764e+04L),
+t07u = LD80C(0xa2f983819a4712aa, 15, 4.17215136963294523085e+04L);
+#define t00 (t00hiu.e)
+#define t00lo (t00lou.e)
+#define t01 (t01hiu.e)
+#define t01lo (t01lou.e)
+#define t02 (t02hiu.e)
+#define t02lo (t02lou.e)
+#define t03 (t03u.e)
+#define t04 (t04u.e)
+#define t05 (t05u.e)
+#define t06 (t06u.e)
+#define t07 (t07u.e)
+
+static const double
+t08 = 1.6688612339742415e+05, /* 0x41045f30, 0xfcb7c9e9 */
+t09 = 6.6753884815733030e+05, /* 0x41245f25, 0xb241ad77 */
+t10 = 2.6704954502371075e+06, /* 0x41445fcf, 0xb9a15e9a */
+t11 = 1.0666012381827524e+07, /* 0x41645803, 0x8c37ee5b */
+t12 = 4.3253268125143178e+07, /* 0x41849ff0, 0xa1004b11 */
+t13 = 1.5587209092892912e+08, /* 0x41a294d6, 0xb5db9c99 */
+t14 = 1.0162479548145952e+09, /* 0x41ce495b, 0x496844a8 */
+t15 = -2.9808831901354914e+09, /* 0xc1e63595, 0x5ec455f2 */
+t16 = 8.5833091951381027e+10, /* 0x4233fc0d, 0x0b6f618b */
+t17 = -6.8395913998321326e+11, /* 0xc263e7e4, 0x87d1e6d3 */
+t18 = 5.1641660627562871e+12, /* 0x4292c981, 0x228a9126 */
+t19 = -2.1258706455671141e+13, /* 0xc2b355ad, 0xa58c7724 */
+t20 = 5.2041706779955102e+13; /* 0x42c7aa73, 0xb91a998d */
+
+static inline long double
+__kernel_tanpil(long double x)
+{
+ long double t, xhi, xlo;
+ uint64_t lx;
+ uint16_t ix;
+
+ xhi = (float)x;
+ xlo = x - xhi;
+ xlo *= (xlo + xhi + xhi);
+ xhi *= xhi;
+
+ if (x < 0.25) {
+#if HORNER
+ long double a, b, c, x2;
+ x2 = xlo + xhi;
+ a = x2 * (x2 * (x2 * (x2 * t20 + t19) + t18) + t17) + t16;
+ b = x2 * (x2 * (x2 * (x2 * a + t15) + t14) + t13) + t12;
+ c = x2 * (x2 * (x2 * (x2 * b + t11) + t10) + t09) + t08;
+ t = x2 * (x2 * (x2 * (x2 * c + t07) + t06) + t05);
+#else
+ long double d, x2, x4;
+ double a, b, c, d2, d4;
+ d2 = x2 = xlo + xhi;
+ d4 = x4 = x2 * x2;
+ a = ((d2 * t20 + t19) * d4 + (d2 * t18 + t17)) * d4;
+ b = ((d2 * t16 + t15) * d4 + (d2 * t14 + t13));
+ c = ((d2 * t12 + t11) * d4 + (d2 * t10 + t09));
+ d = ((x2 * t08 + t07) * x4 + (x2 * t06 + t05));
+ t = (((a * d4 + b) * (x4 * x4) + c) * (x4 * x4) + d) * x2;
+#endif
+ t = t02lo + x2 * (x2 * (t + t04) + t03) + t02;
+ t = t01lo + xlo * t + xhi * t + t01;
+ t = t00lo + xlo * t + xhi * t + t00;
+ return (t * x);
+ } else if (x > 0.25) {
+ x = 0.5 - x;
+ t = __kernel_cospil(x) / __kernel_sinpil(x);
+ } else
+ t = 1;
+ return (t);
+}
+
+static inline long double
+__compute_tanpil(long double x)
+{
+
+ return (x < 0.5 ? __kernel_tanpil(x) : -__kernel_tanpil(1 - x));
+}
+
+long double
+tanpil(long double x)
+{
+ volatile static const double vzero = 0;
+ long double ax;
+ uint32_t j0;
+ uint64_t lx;
+ uint16_t hx, ix;
+
+ EXTRACT_LDBL80_WORDS(hx, lx, x);
+ ix = hx & 0x7fff;
+ INSERT_LDBL80_WORDS(ax, ix, lx);
+
+ ENTERI();
+
+ if (ix < 0x3fff) { /* |x| < 1 */
+ if (ix < 0x3fdd) { /* |x| < 0x1p-34 */
+ if (x == 0)
+ RETURNI(x);
+ INSERT_LDBL80_WORDS(ax, ix, (lx >> 32) << 32);
+ x -= ax;
+ RETURNI(pilo * x + pihi * x + pilo * ax + pihi * ax);
+ }
+ if (ix == 0x3ffe && lx == 0x8000000000000000ull)
+ RETURNI((x - x) / (x - x));
+ ax = __compute_tanpil(ax);
+ RETURNI((hx & 0x8000) ? -ax : ax);
+ }
+
+ if (ix < 0x403e) { /* 1 <= |x| < 0x1p63 */
+ /* Determine integer part of ax. */
+ j0 = ix - 0x3fff + 1;
+ if (j0 < 32) {
+ lx = (lx >> 32) << 32;
+ lx &= ~(((lx << 32)-1) >> j0);
+ } else {
+ uint64_t m = (uint64_t)-1 >> (j0 + 1);
+ if (lx & m) lx &= ~m;
+ }
+ INSERT_LDBL80_WORDS(x, ix, lx);
+
+ ax -= x;
+
+ if (ax == 0.5)
+ RETURNI((x - x) / (x - x));
+
+ ax = ax == 0 ? 0 : __compute_tanpil(ax);
+ RETURNI((hx & 0x8000) ? -ax : ax);
+ }
+
+ /* x = +-inf or nan. */
+ if (ix >= 0x7fff)
+ RETURNI(vzero / vzero);
+
+ /*
+ * |x| >= 0x1p63 is always an integer, so return +-0.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID.
+ */
+ if (ax + 1 > 1)
+ ax = copysignl(0, x);
+ RETURNI(ax);
+}
Property changes on: lib/msun/ld80/s_tanpil.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/man/cospi.3
===================================================================
--- lib/msun/man/cospi.3 (nonexistent)
+++ lib/msun/man/cospi.3 (working copy)
@@ -0,0 +1,111 @@
+.\" Copyright (c) 2017 Steven G. Kargl <kargl at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" 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 REGENTS 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 REGENTS 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd April 1, 2017
+.Dt COSPI 3
+.Os
+.Sh NAME
+.Nm cospi ,
+.Nm cospif ,
+.Nm cospil
+.Nd half\(encycle cosine functions
+.Sh LIBRARY
+.Lb libm
+.Sh SYNOPSIS
+.In math.h
+.Ft double
+.Fn cospi "double x"
+.Ft float
+.Fn cospif "float x"
+.Ft long double
+.Fn cospil "long double x"
+.Sh DESCRIPTION
+The
+.Fn cospi ,
+.Fn cospif ,
+and
+.Fn cospil
+functions compute the cosine of
+.Fa "\(*p \(mu x" .
+and measure angles in half-cycles.
+.Sh RETURN VALUES
+The
+.Fn cospi ,
+.Fn cospif ,
+and
+.Fn cospil
+functions returns
+.Fn cos "\(*p \(mu x" .
+If \*(Bax\*(Ba \*(Ge 2^(p - 1)
+where p is the floating\(enpoint precision of
+.Ar x ,
+then the returned value is 1 and it has no significance.
+.Sh SPECIAL VALUES
+.Bl -tag
+.It
+.Fn cospi \*(Pm0
+returns 1.
+.It
+.Fn cospi \*(Pmn/2
+returns 0 for positive integers
+.Ar n .
+.It
+.Fn cospi n
+returns 1 for even integers
+.Ar n .
+.It
+.Fn cospi n
+returns \-1 for odd integers
+.Ar n .
+.It
+.Fn cospi \*(Pm\(if
+return an \*(Na and raises an FE_INVALID exception.
+.It
+.Fn cospi \*(Na
+return an \*(Na and raises an FE_INVALID exception.
+.El
+.Sh SEE ALSO
+.Xr cos 3 ,
+.Xr fenv 3 ,
+.Xr math 3 ,
+.Xr sin 3 ,
+.Xr sinpi 3 ,
+.Xr tan 3 ,
+.Xr tanpi 3
+.Sh AUTHORS
+The half\(encycle trignometric functions were written by
+.An Steven G. Kargl Aq Mt kargl at FreeBSD.org .
+.Sh STANDARDS
+These functions conform to
+IEEE Std 754\(tm\(en2008 ,
+\(dqIEEE Standard for Floating-Point Arithmetic\(dq
+and to
+ISO/IEC TS 18661-4 ,
+\(dqInformation technology \(em Programming languages, their environments,
+and system software interfaces \(em Floating\(enpoint extensions for
+C\(dq \(em Part 4: Supplementary functions.
+
+
Property changes on: lib/msun/man/cospi.3
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/man/sinpi.3
===================================================================
--- lib/msun/man/sinpi.3 (nonexistent)
+++ lib/msun/man/sinpi.3 (working copy)
@@ -0,0 +1,102 @@
+.\" Copyright (c) 2017 Steven G. Kargl <kargl at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" 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 REGENTS 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 REGENTS 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd April 1, 2017
+.Dt SINPI 3
+.Os
+.Sh NAME
+.Nm sinpi ,
+.Nm sinpif ,
+.Nm sinpil
+.Nd half\(encycle sine functions
+.Sh LIBRARY
+.Lb libm
+.Sh SYNOPSIS
+.In math.h
+.Ft double
+.Fn sinpi "double x"
+.Ft float
+.Fn sinpif "float x"
+.Ft long double
+.Fn sinpil "long double x"
+.Sh DESCRIPTION
+The
+.Fn sinpi ,
+.Fn sinpif ,
+and
+.Fn sinpil
+functions compute the sine of
+.Fa "\(*p \(mu x" .
+and measure angles in half-cycles.
+.Sh RETURN VALUES
+The
+.Fn sinpi ,
+.Fn sinpif ,
+and
+.Fn sinpil
+functions returns
+.Fn sin "\(*p \(mu x" .
+If \*(Bax\*(Ba \*(Ge 2^(p - 1)
+where p is the floating\(enpoint precision of
+.Ar x ,
+then the returned value is \*(Pm0 and it has no significance.
+.Sh SPECIAL VALUES
+.Bl -tag
+.It
+.Fn sinpi \*(Pm0
+returns \*(Pm0.
+.It
+.Fn sinpi \*(Pmn
+returns \*(Pm0 for positive integers
+.Ar n .
+.It
+.Fn sinpi \*(Pm\(if
+return an \*(Na and raises an FE_INVALID exception.
+.It
+.Fn sinpi \*(Na
+return an \*(Na and raises an FE_INVALID exception.
+.El
+.Sh SEE ALSO
+.Xr cos 3 ,
+.Xr cospi 3 ,
+.Xr fenv 3 ,
+.Xr math 3 ,
+.Xr sin 3 ,
+.Xr tan 3 ,
+.Xr tanpi 3
+.Sh AUTHORS
+The half\(encycle trignometric functions were written by
+.An Steven G. Kargl Aq Mt kargl at FreeBSD.org .
+.Sh STANDARDS
+These functions conform to
+IEEE Std 754\(tm\(en2008 ,
+\(dqIEEE Standard for Floating-Point Arithmetic\(dq
+and to
+ISO/IEC TS 18661-4 ,
+\(dqInformation technology \(em Programming languages, their environments,
+and system software interfaces \(em Floating\(enpoint extensions for
+C\(dq \(em Part 4: Supplementary functions.
+
Property changes on: lib/msun/man/sinpi.3
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/man/tanpi.3
===================================================================
--- lib/msun/man/tanpi.3 (nonexistent)
+++ lib/msun/man/tanpi.3 (working copy)
@@ -0,0 +1,106 @@
+.\" Copyright (c) 2017 Steven G. Kargl <kargl at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" 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 REGENTS 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 REGENTS 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd April 1, 2017
+.Dt TANPI 3
+.Os
+.Sh NAME
+.Nm tanpi ,
+.Nm tanpif ,
+.Nm tanpil
+.Nd half\(encycle tangent functions
+.Sh LIBRARY
+.Lb libm
+.Sh SYNOPSIS
+.In math.h
+.Ft double
+.Fn tanpi "double x"
+.Ft float
+.Fn tanpif "float x"
+.Ft long double
+.Fn tanpil "long double x"
+.Sh DESCRIPTION
+The
+.Fn tanpi ,
+.Fn tanpif ,
+and
+.Fn tanpil
+functions compute the tangent of
+.Fa "\(*p \(mu x"
+and measure angles in half-cycles.
+.Sh RETURN VALUES
+The
+.Fn tanpi ,
+.Fn tanpif ,
+and
+.Fn tanpil
+functions returns
+.Fn tan "\(*p \(mu x" .
+If \*(Bax\*(Ba \*(Ge 2^(p - 1)
+where p is the floating\(enpoint precision of
+.Ar x ,
+then the returned value is \*(Pm0 and it has no significance.
+.Sh SPECIAL VALUES
+.Bl -tag
+.It
+.Fn tanpi \*(Pm0
+returns \*(Pm0.
+.It
+.Fn tanpi \*(Pmn
+returns \*(Pm0 for positive integers
+.Ar n .
+.It
+.Fn tanpi \*(Pmn/2
+returns \*(Na for n > 0 and raises an FE_INVALID exception.
+.It
+.Fn tanpi \*(Pm\(if
+return an \*(Na and raises an FE_INVALID exception.
+.It
+.Fn tanpi \*(Na
+return an \*(Na and raises an FE_INVALID exception.
+.El
+.Sh SEE ALSO
+.Xr cos 3 ,
+.Xr cospi 3 ,
+.Xr fenv 3 ,
+.Xr math 3 ,
+.Xr sin 3 ,
+.Xr sinpi 3 ,
+.Xr tan 3 ,
+.Sh AUTHORS
+The half\(encycle trignometric functions were written by
+.An Steven G. Kargl Aq Mt kargl at FreeBSD.org .
+.Sh STANDARDS
+These functions conform to
+IEEE Std 754\(tm\(en2008 ,
+\(dqIEEE Standard for Floating-Point Arithmetic\(dq
+and to
+ISO/IEC TS 18661-4 ,
+\(dqInformation technology \(em Programming languages, their environments,
+and system software interfaces \(em Floating\(enpoint extensions for
+C\(dq \(em Part 4: Supplementary functions.
+
+
Property changes on: lib/msun/man/tanpi.3
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/k_cospi.c
===================================================================
--- lib/msun/src/k_cospi.c (nonexistent)
+++ lib/msun/src/k_cospi.c (working copy)
@@ -0,0 +1,83 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * Compute cospi(x) = cos(pi*x) via a polynomial approximation. Coefficients
+ * were determined for the following function:
+ *
+ * f(x) = ((cos(pi*x) - 1) / (x*x)) = c1 + c2*x**2 + c3*x**4 + ...
+ *
+ * with an Remes algorithm. If |x*x| < 0x1p-6, the polynomial can be summed
+ * using a Horner's method. If |x*x| exceeds 0x1p-6, then to accumulate the
+ * result with sufficient accuracy the c1 coefficient and final
+ * multiplications needed to be handled specially.
+ *
+ * x2 = x * x
+ * C(x2) = c1hi + c2*x2 + c3*x2**2 + ...
+ * = c1hi + (c2 + (c3 ...) * x2) * x2
+ * cospi(x) = c0 + x2 * C(x2)
+ */
+
+static const double
+c0 = 1.0000000000000000e+00, /* 0x3ff00000 0x00000000 */
+c1hi = -4.9348022005446790e+00, /* 0xc013bd3c 0xc9be45de */
+c1lo = -3.1132368291465357e-16, /* 0xbcb66ee8 0x86887579 */
+c2 = 4.0587121264167649e+00, /* 0x40103c1f 0x081b5ac0 */
+c3 = -1.3352627688538099e+00, /* 0xbff55d3c 0x7e3cb243 */
+c4 = 2.3533063028402096e-01, /* 0x3fce1f50 0x68689166 */
+c5 = -2.5806887965588832e-02, /* 0xbf9a6d1e 0xef4b8280 */
+c6 = 1.9294938875092037e-03, /* 0x3f5f9ce2 0x49428066 */
+c7 = -1.0370089699114971e-04; /* 0xbf1b2f3f 0xd835d4fe */
+
+static inline double
+__kernel_cospi(double x)
+{
+ double c, chi, clo, x2hi, x2lo;
+#if HORNER
+ /* Horner's method. */
+ double x2;
+ x2 = x * x;
+ c = (c2 + (c3 + (c4 + (c5 + (c6 + c7 * x2) * x2) * x2) * x2)
+ * x2) * x2 + c1hi;
+#else
+ /* Sort of Estrin's method. */
+ double x2, x4;
+ x2 = x * x;
+ x4 = x2 * x2;
+ c = (c5 + c6 * x2 + c7 * x4) * (x4 * x4)
+ + (c2 + c3 * x2 + c4 * x4) * x2 + c1hi;
+#endif
+ if (x2 < 0x1p-6)
+ return (c0 + c * x2);
+
+ x2hi = (float)x2;
+ x2lo = x2 - x2hi;
+ chi = (float)c;
+ clo = c - chi + c1lo;
+ c = clo * x2lo + (chi * x2lo + clo * x2hi) + (chi * x2hi + c0);
+
+ return (c);
+}
Property changes on: lib/msun/src/k_cospi.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/k_cospif.c
===================================================================
--- lib/msun/src/k_cospif.c (nonexistent)
+++ lib/msun/src/k_cospif.c (working copy)
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/k_cospi.c for implementation details.
+ */
+
+static const float
+c0 = 1.00000000e+00f, /* 0x3fc00000 */
+c1hi = -4.93480206e+00f, /* 0xc09de9e6 0xb418a08d */
+c1lo = -1.42145112e-07f, /* 0xc09de9e6 0xb418a08d */
+c2 = 4.05871058e+00f, /* 0x4081e0f5 0xb1fc37ea */
+c3 = -1.33513784e+00f, /* 0xbfaae5cc 0xb375e792 */
+c4 = 2.32126340e-01f; /* 0x3e6db287 0x31daa25f */
+
+static inline float
+__kernel_cospif(float x)
+{
+ float c, chi, clo, x2, x2hi, x2lo;
+ uint32_t ix;
+
+ x2 = x * x;
+ c = (c2 + (c3 + c4 * x2) * x2) * x2 + c1hi;
+
+ GET_FLOAT_WORD(ix, x2);
+ if (ix < 0x3c800000) /* |x2| < 0x1p-6 */
+ return (c0 + c * x2);
+
+ SET_FLOAT_WORD(x2hi, (ix >> 14) << 14);
+ x2lo = x2 - x2hi;
+ GET_FLOAT_WORD(ix, c);
+ SET_FLOAT_WORD(chi, (ix >> 14) << 14);
+ clo = c - chi + c1lo;
+ c = clo * x2lo + chi * x2lo + clo * x2hi + (chi * x2hi + c0);
+
+ return (c);
+}
Property changes on: lib/msun/src/k_cospif.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/k_sinpi.c
===================================================================
--- lib/msun/src/k_sinpi.c (nonexistent)
+++ lib/msun/src/k_sinpi.c (working copy)
@@ -0,0 +1,84 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * Compute sinpi(x) = sin(pi*x) via a polynomial approximation. Coefficients
+ * were determined for the following function:
+ *
+ * f(x) = sin(pi*x) / x = s0 + s1*x**2 + s2*x**4 + ...
+ *
+ * with an Remes algorithm. To accumulate the result with sufficient
+ * accuracy the s0 coefficient and final multiplications needed to be
+ * handled specially.
+ *
+ * x2 = x * x
+ * S(x2) = s1 + s2*x2 + s3*x2**2 + ...
+ * = s1 + (s2 + (s3 ...) * x2) * x2
+ * sinpi(x) = x * (s0 + x2 * S(x2))
+ *
+ * The final multiplications and additions in the above expression for
+ * sinpi(x) are done in an extra precision arithmetic.
+ */
+
+static const double
+s0hi = 3.1415926218032837e+00, /* 0x400921fb 0x50000000 */
+s0lo = 3.1786509547050787e-08, /* 0x3e6110b4 0x611a5f14 */
+s1 = -5.1677127800499703e+00, /* 0xc014abbc 0xe625be53 */
+s2 = 2.5501640398773415e+00, /* 0x400466bc 0x6775aad9 */
+s3 = -5.9926452932029806e-01, /* 0xbfe32d2c 0xce62ac24 */
+s4 = 8.2145886580065136e-02, /* 0x3fb50783 0x485cc006 */
+s5 = -7.3704298849218506e-03, /* 0xbf7e3074 0xb502de6a */
+s6 = 4.6628273194622205e-04, /* 0x3f3e8eed 0x159b24d7 */
+s7 = -2.1717412527405332e-05; /* 0xbef6c5b9 0x3995dfbe */
+
+static inline double
+__kernel_sinpi(double x)
+{
+ double hi, lo, sm, xhi, xlo;
+ uint32_t hx, lx;
+#if HORNER
+ double x2;
+ /* Horner's method. */
+ x2 = x * x;
+ sm = x2 * (x2 * (x2 * (x2 * (x2 * (x2 * s7 + s6) + s5) + s4) + s3)
+ + s2) + s1;
+#else
+ double x2, x4;
+ /* Sort of Estrin's method. */
+ x2 = x * x;
+ x4 = x2 * x2;
+ sm = (s5 + s6 * x2 + s7 * x4) * (x4 * x4)
+ + (s2 + s3 * x2 + s4 * x4) * x2 + s1;
+#endif
+ EXTRACT_WORDS(hx, lx, x);
+ INSERT_WORDS(xhi, hx, 0);
+ xlo = x - xhi;
+ lo = xlo * (x + xhi) * sm;
+ hi = xhi * xhi * sm;
+ lo = x * lo + xlo * (s0hi + s0lo) + x * hi;
+
+ return (lo + xhi * s0lo + xhi * s0hi);
+}
Property changes on: lib/msun/src/k_sinpi.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/k_sinpif.c
===================================================================
--- lib/msun/src/k_sinpif.c (nonexistent)
+++ lib/msun/src/k_sinpif.c (working copy)
@@ -0,0 +1,56 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/k_sinpi.c for implementation details.
+ */
+
+static const float
+s0hi = 3.14062500e+00f, /* 0x40490000 */
+s0lo = 9.67653585e-04f, /* 0x3a7daa22 */
+s1 = -5.16771269e+00f, /* 0xc0a55de7 */
+s2 = 2.55016255e+00f, /* 0x402335dd */
+s3 = -5.99202096e-01f, /* 0xbf19654f */
+s4 = 8.10018554e-02f; /* 0x3da5e44d */
+
+static inline float
+__kernel_sinpif(float x)
+{
+ float hi, lo, sm, x2, xhi, xlo;
+ uint32_t ix;
+
+ GET_FLOAT_WORD(ix, x);
+ SET_FLOAT_WORD(xhi, (ix >> 14) << 14);
+ xlo = x - xhi;
+
+ x2 = x * x;
+ sm = x2 * (x2 * (x2 * s4 + s3) + s2) + s1;
+ lo = xlo * (x + xhi) * sm;
+ hi = xhi * xhi * sm;
+ lo = x * lo + xlo * (s0hi + s0lo) + x * hi;
+
+ return (lo + xhi * s0lo + xhi * s0hi);
+}
Property changes on: lib/msun/src/k_sinpif.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/math.h
===================================================================
--- lib/msun/src/math.h (revision 317529)
+++ lib/msun/src/math.h (working copy)
@@ -500,6 +500,15 @@
#if __BSD_VISIBLE
long double lgammal_r(long double, int *);
+double cospi(double);
+float cospif(float);
+long double cospil(long double);
+double sinpi(double);
+float sinpif(float);
+long double sinpil(long double);
+double tanpi(double);
+float tanpif(float);
+long double tanpil(long double);
#endif
__END_DECLS
Index: lib/msun/src/s_cospi.c
===================================================================
--- lib/msun/src/s_cospi.c (nonexistent)
+++ lib/msun/src/s_cospi.c (working copy)
@@ -0,0 +1,147 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/**
+ * cospi(x) computes cos(pi*x) without multiplication by pi (almost). First,
+ * note that cospi(-x) = cospi(x), so the algorithm considers only |x|. The
+ * method used depends on the magnitude of x.
+ *
+ * 1. For small |x|, cospi(x) = 1 with FE_INEXACT raised where a sloppy
+ * threshold is used. The threshold is |x| < 0x1pN with N = -(P/2+M).
+ * P is the precision of the floating-point type and M = 3 or 4.
+ *
+ * 2. For |x| < 1, argument reduction is not required and cospi(x) is
+ * computed by polynomial approximations in the the interval [0,0.25].
+ * See k_sinpi.c and k_cospi.c for the details for these polynomial
+ * approximations.
+ *
+ * 3. For 1 <= |x| < 0x1p(P-1), argument reduction is required where
+ * |x| = j0 + r with j0 an integer and the remainder r statisfies
+ * 0 <= r < 1. With the given domain, a simplified inline floor(x)
+ * is used.
+ *
+ * cospi(x) = cos(pi*(j0+r))
+ * = cos(pi*j0) * cos(pi*r) - sin(pi*j0) * sin(pi*r)
+ * = cos(pi*j0) * cos(pi*r)
+ * = +-cospi(r)
+ *
+ * If j0 is even, then cos(pi*j0) = 1. If j0 is odd, then cos(pi*j0) = -1.
+ * cospi(r) is then computed via polynomial approximation.
+ *
+ * 4. For |x| >= 0x1p(P-1), |x| is integral and cospi(x) = 1.
+ *
+ * 5. Special cases:
+ *
+ * cospi(+-0) = 1.
+ * cospi(n.5) = 0 for n an integer.
+ * cospi(+-inf) = nan. Raises the "invalid" floating-point exception.
+ * cospi(nan) = nan. Raises the "invalid" floating-point exception.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_cospi.c"
+#include "k_sinpi.c"
+
+/*
+ * To compute cospi(x) for 0 < x < 1, use trignometric identities to map
+ * cospi(x) into the [0,0.25] quadrant of sinpi(r) or cospi(r).
+ */
+static inline double
+__compute_cospi(double x)
+{
+
+ if (x < 0.5) {
+ if (x < 0.25)
+ return (__kernel_cospi(x));
+ return (__kernel_sinpi(0.5 - x));
+ } else {
+ if (x < 0.75)
+ return (-__kernel_sinpi(x - 0.5));
+ return (-__kernel_cospi(1 - x));
+ }
+}
+
+double
+cospi(double x)
+{
+ volatile static const double vzero = 0;
+ static const double huge = 1e+300;
+ double ax;
+ uint32_t hx, ix, j0, lx;
+
+ EXTRACT_WORDS(hx, lx, x);
+ ix = hx & 0x7fffffff;
+ INSERT_WORDS(ax, ix, lx);
+
+ if (ix < 0x3ff00000) { /* |x| < 1 */
+ if (ix < 0x3e200000) { /* |x| < 0x1p-29 */
+ if (huge + x > 0)
+ return (1);
+ }
+ if ((ix | lx) == 0x3fe00000)
+ return (0);
+ return (__compute_cospi(ax));
+ }
+
+ if (ix < 0x43300000) { /* 1 <= |x| < 0x1p52 */
+ /* Determine integer part of ax. */
+ j0 = ((ix >> 20) & 0x7ff) - 0x3ff;
+ if (j0 < 20) {
+ ix &= ~(0x000fffff >> j0);
+ lx = 0;
+ } else {
+ lx &= ~((uint32_t)0xffffffff >> (j0 - 20));
+ }
+ INSERT_WORDS(x, ix, lx);
+
+ ax -= x;
+ if (ax == 0.5)
+ return (0);
+
+ ax = ax == 0 ? 1 : __compute_cospi(ax);
+
+ if (j0 > 30) x -= 0x1p30;
+ j0 = (uint32_t)x;
+
+ return (j0 & 1 ? -ax : ax);
+ }
+
+ if (ix >= 0x7f800000)
+ return (vzero / vzero);
+
+ /*
+ * |x| >= 0x1p52 is always an even integer, so return 1.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID?
+ */
+ if (ax + 1 > 1)
+ ax = 1;
+ return (ax);
+}
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(cospi, cospil);
+#endif
Property changes on: lib/msun/src/s_cospi.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/s_cospif.c
===================================================================
--- lib/msun/src/s_cospif.c (nonexistent)
+++ lib/msun/src/s_cospif.c (working copy)
@@ -0,0 +1,99 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/s_cospi.c for implementation details.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_cospif.c"
+#include "k_sinpif.c"
+
+static inline float
+__compute_cospif(float x)
+{
+
+ if (x <= 0.5f) {
+ if (x <= 0.25f)
+ return (__kernel_cospif(x));
+ return (__kernel_sinpif(0.5f - x));
+ } else {
+ if (x <= 0.75f)
+ return (-__kernel_sinpif(x - 0.5f));
+ return (-__kernel_cospif(1 - x));
+ }
+}
+
+float
+cospif(float x)
+{
+ volatile static const float vzero = 0;
+ static const float huge = 1e30;
+ float ax;
+ uint32_t ix, j0;
+
+ GET_FLOAT_WORD(ix, x);
+ ix = ix & 0x7fffffff;
+ SET_FLOAT_WORD(ax, ix);
+
+ if (ix < 0x3f800000) { /* |x| < 1 */
+ if (ix < 0x39000000) { /* |x| < 0x1p-13 */
+ if (huge + ax > 0) /* Raise inexact iff != 0. */
+ return (1);
+ }
+ return (__compute_cospif(ax));
+ }
+
+ if (ix < 0x4b000000) { /* 1 <= |x| < 0x1p23 */
+ /* Determine integer part of ax. */
+ j0 = ((ix >> 23) & 0xff) - 0x7f;
+ ix &= ~(0x007fffff >> j0);
+ SET_FLOAT_WORD(x, ix);
+
+ ax -= x;
+ if (ax == 0.5f)
+ return (0);
+
+ ax = ax == 0 ? 1 : __compute_cospif(ax);
+
+ ix = (uint32_t)x;
+
+ return (ix & 1 ? -ax : ax);
+ }
+
+ /* x = +-inf or nan. */
+ if (ix >= 0x7f800000)
+ return (vzero / vzero);
+
+ /*
+ * |x| >= 0x1p23 is always an even integer, so return 1.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID.
+ */
+ if (ax + 1 > 1)
+ ax = 1;
+ return (ax);
+}
Property changes on: lib/msun/src/s_cospif.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/s_sinpi.c
===================================================================
--- lib/msun/src/s_sinpi.c (nonexistent)
+++ lib/msun/src/s_sinpi.c (working copy)
@@ -0,0 +1,154 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/**
+ * sinpi(x) computes sin(pi*x) without multiplication by pi (almost). First,
+ * note that sinpi(-x) = -sinpi(x), so the algorithm considers only |x| and
+ * includes reflection symmetry by considering the sign of x on output. The
+ * method used depends on the magnitude of x.
+ *
+ * 1. For small |x|, sinpi(x) = pi * x where a sloppy threshold is used. The
+ * threshold is |x| < 0x1pN with N = -(P/2+M). P is the precision of the
+ * floating-point type and M = 3 or 4. To achieve high accuracy, pi is
+ * decomposed into high and low parts with the high part containing a
+ * number of trailing zero bits. x is also split into high and low parts.
+ *
+ * 2. For |x| < 1, argument reduction is not required and sinpi(x) is
+ * computed by polynomial approximations in the the interval [0,0.25].
+ * See k_sinpi.c and k_cospi.c for the details for these polynomial
+ * approximations.
+ *
+ * 3. For 1 <= |x| < 0x1p(P-1), argument reduction is required where
+ * |x| = j0 + r with j0 an integer and the remainder r satisifies
+ * 0 <= r < 1. With the given domain, a simplified inline floor(x)
+ * is used.
+ *
+ * sinpi(x) = sin(pi*(j0+r))
+ * = sin(pi*j0) * cos(pi*r) + cos(pi*j0) * sin(pi*r)
+ * = cos(pi*j0) * sin(pi*r)
+ * = +-sinpi(r)
+ *
+ * If j0 is even, then cos(pi*j0) = 1. If j0 is odd, then cos(pi*j0) = -1.
+ * sinpi(r) is then computed via polynomial approximation.
+ *
+ * 4. For |x| >= 0x1p(P-1), |x| is integral and sinpi(x) = copysign(0,x).
+ *
+ * 5. Special cases:
+ *
+ * sinpi(+-0) = +-0
+ * sinpi(+-n) = +-0, for positive integers n.
+ * sinpi(+-inf) = nan. Raises the "invalid" floating-point exception.
+ * sinpi(nan) = nan. Raises the "invalid" floating-point exception.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_cospi.c"
+#include "k_sinpi.c"
+
+static const double pihi = 3.1415926814079285e+00; /* 0x400921fb 0x58000000 */
+static const double pilo =-2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */
+
+/*
+ * To compute sinpi(x) for 0 < x < 1, use trignometric identities to map
+ * sinpi(x) into the [0,0.25] quadrant of sinpi(r) or cospi(r).
+ */
+static inline double
+__compute_sinpi(double x)
+{
+
+ if (x < 0.5) {
+ if (x < 0.25)
+ return (__kernel_sinpi(x));
+ return (__kernel_cospi(0.5 - x));
+ } else {
+ if (x < 0.75)
+ return (__kernel_cospi(x - 0.5));
+ return (__kernel_sinpi(1 - x));
+ }
+}
+
+double
+sinpi(double x)
+{
+ volatile static const double vzero = 0;
+ double ax;
+ uint32_t hx, ix, j0, lx;
+
+ EXTRACT_WORDS(hx, lx, x);
+ ix = hx & 0x7fffffff;
+ INSERT_WORDS(ax, ix, lx);
+
+ if (ix < 0x3ff00000) { /* |x| < 1 */
+ if (ix < 0x3e300000) { /* |x| < 0x1p-28 */
+ if (x == 0)
+ return (x);
+ INSERT_WORDS(ax, hx, 0);
+ x -= ax;
+ return (pilo * x + pihi * x + pilo * ax + pihi * ax);
+ }
+ ax = __compute_sinpi(ax);
+ return ((hx & 0x80000000) ? -ax : ax);
+ }
+
+ if (ix < 0x43300000) { /* 1 <= |x| < 0x1p52 */
+ /* Determine integer part of ax. */
+ j0 = ((ix >> 20) & 0x7ff) - 0x3ff;
+ if (j0 < 20) {
+ ix &= ~(0x000fffff >> j0);
+ lx = 0;
+ } else {
+ lx &= ~((uint32_t)0xffffffff >> (j0 - 20));
+ }
+ INSERT_WORDS(x, ix, lx);
+
+ ax -= x;
+ if (ax == 0) {
+ ax = 0;
+ } else {
+ ax = __compute_sinpi(ax);
+ if (j0 > 30) x -= 0x1p30;
+ lx = (uint32_t)x;
+ if (lx & 1) ax = -ax;
+ }
+ return ((hx & 0x80000000) ? -ax : ax);
+ }
+
+ if (ix >= 0x7f800000)
+ return (vzero / vzero);
+
+ /*
+ * |x| >= 0x1p52 is always an integer, so return +-0.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID?
+ */
+ if (ax + 1 > 1)
+ ax = copysign(0, x);
+ return (ax);
+}
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(sinpi, sinpil);
+#endif
Property changes on: lib/msun/src/s_sinpi.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/s_sinpif.c
===================================================================
--- lib/msun/src/s_sinpif.c (nonexistent)
+++ lib/msun/src/s_sinpif.c (working copy)
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/s_sinpi.c for implementation details.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_cospif.c"
+#include "k_sinpif.c"
+
+static inline float
+__compute_sinpif(float x)
+{
+
+ if (x <= 0.5f) {
+ if (x <= 0.25f)
+ return (__kernel_sinpif(x));
+ return (__kernel_cospif(0.5f - x));
+ } else {
+ if (x <= 0.75f)
+ return (__kernel_cospif(x - 0.5f));
+ return (__kernel_sinpif(1 - x));
+ }
+}
+
+static const float pihi = 3.14160156e+00f; /* 0x40491000 */
+static const float pilo = -8.90890988e-06f; /* 0xb715777a */
+
+float
+sinpif(float x)
+{
+ volatile static const float vzero = 0;
+ float ax;
+ uint32_t hx, ix, j0;
+
+ GET_FLOAT_WORD(hx, x);
+ ix = hx & 0x7fffffff;
+ SET_FLOAT_WORD(ax, ix);
+
+ if (ix < 0x3f800000) { /* |x| < 1 */
+ if (ix < 0x38000000) { /* |x| < 0x1p-15 */
+ if (x == 0)
+ return (x);
+ SET_FLOAT_WORD(ax, (hx >> 13) << 13);
+ x -= ax;
+ return (pilo * x + pihi * x + pilo * ax + pihi * ax);
+ }
+ ax = __compute_sinpif(ax);
+ return ((hx & 0x80000000) ? -ax : ax);
+ }
+
+ if (ix < 0x4b000000) { /* 1 <= |x| < 0x1p23 */
+ /* Determine integer part of ax. */
+ j0 = ((ix >> 23) & 0xff) - 0x7f;
+ ix &= ~(0x007fffff >> j0);
+ SET_FLOAT_WORD(x, ix);
+
+ ax -= x;
+ if (ax == 0) {
+ ax = 0;
+ } else {
+ ix = (uint32_t)x;
+ ax = __compute_sinpif(ax);
+ if (ix & 1) ax = -ax;
+ }
+ return ((hx & 0x80000000) ? -ax : ax);
+ }
+
+ /* x = +-inf or nan. */
+ if (ix >= 0x7f800000)
+ return (vzero / vzero);
+
+ /*
+ * |x| >= 0x1p23 is always an integer, so return +-0.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID?
+ */
+ if (ax + 1 > 1)
+ ax = copysignf(0, x);
+ return (ax);
+}
Property changes on: lib/msun/src/s_sinpif.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/s_tanpi.c
===================================================================
--- lib/msun/src/s_tanpi.c (nonexistent)
+++ lib/msun/src/s_tanpi.c (working copy)
@@ -0,0 +1,224 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/**
+ * tanpi(x) computes tan(pi*x) without multiplication by pi (almost). First,
+ * note that tanpi(-x) = -tanpi(x), so the algorithm considers only |x| and
+ * includes reflection symmetry by considering the sign of x on output. The
+ * method used depends on the magnitude of x.
+ *
+ * 1. For small |x|, tanpi(x) = pi * x where a sloppy threshold is used. The
+ * threshold is |x| < 0x1pN with N = -(P/2+M). P is the precision of the
+ * floating-point type and M = 3 or 4. To achieve high accuracy, pi is
+ * decomposed into high and low parts with the high part containing a
+ * number of trailing zero bits. x is also split into high and low parts.
+ *
+ * 2. For |x| < 1, argument reduction is not required and tanpi(x) is
+ * computed by either a polynomial approximation or the definition of
+ * tanpi in terms of sinpi and cospi. For |x| in [0,0.25), a polynomial
+ * approximation is used. For |x| in (0.25, 0.5], tanpi(x) is computed
+ * by tanpi(x) = cospi(0.5 - x) / sinpi(0.5 - x).
+ *
+ * 3. For 1 <= |x| < 0x1p(P-1), argument reduction is required where
+ * |x| = j0 + r with j0 an integer and the remainder r satisfies
+ * 0 <= r < 1. With the given domain, a simplified inline floor(x)
+ * is used.
+ * tan(pi*j0) + tan(pi*r)
+ * tanpi(x) = tan(pi*(j0+r)) = ---------------------------- = tanpi(r)
+ * 1 - tan(pi*j0) * tan(pi*r)
+ *
+ * 4. For |x| >= 0x1p(P-1), |x| is integral and tanpi(x) = copysign(0,x).
+ *
+ * 5. Special cases:
+ *
+ * tanpi(+-0) = +-0
+ * tanpi(+-n) = +-0, for positive integers n.
+ * tanpi(+-n+1/4) = +-1, for positive integers n.
+ * tanpi(+-n+1/2) = NaN, for positive integers n.
+ * tanpi(+-inf) = nan. Raises the "invalid" floating-point exception.
+ * tanpi(nan) = nan. Raises the "invalid" floating-point exception.
+ *
+ * Compute tanpi(x) = tan(pi*x) via a polynomial approximation. Coefficients
+ * were determined for the following function:
+ *
+ * f(x) = tan(pi*x) / x = t0 + t1*x**2 + t2*x**4 + ...
+ *
+ * with an Remes algorithm. To accumulate the result with sufficient accuracy,
+ * the t0, t1, and t2 coefficients and final multiplications and additions
+ * needed to be handled specially.
+ *
+ * x2 = x * x
+ * T(x2) = t3 + t4*x2 + t5*x2**2 + ...
+ * = t3 + (t4 + (t5 ...) * x2) * x2
+ * tanpi(x) = x * (t0 + x2*(t1 + x2*(t2 + x2*T(x2))))
+ *
+ * The final multiplications and additions in the above expression for
+ * tanpi(x) are done in an extra precision arithmetic.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_cospi.c"
+#include "k_sinpi.c"
+
+static const double pihi = 3.1415926814079285e+00; /* 0x400921fb 0x58000000 */
+static const double pilo =-2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */
+
+static const double
+t00 = 3.1415926535897931e+00, /* 0x400921fb 0x54442d18 */
+t00lo = 1.2267625636978282e-16, /* 0x3ca1adf4 0x7b8ee56b */
+t01 = 1.0335425560099939e+01, /* 0x4024abbc 0xe625be52 */
+t01lo = -6.0289590484334045e-16, /* 0xbcc5b8bb 0xb4f3d850 */
+t02 = 4.0802624638040442e+01, /* 0x404466bc 0x6775ac7c */
+t02lo = -3.1181465177803440e-15, /* 0xbcec15f4 0xd355f491 */
+t03 = 1.6299995197351416e+02, /* 0x40645fff 0x9b47fa0c */
+t04 = 6.5190975669363422e+02, /* 0x40845f47 0x2e8473cf */
+t05 = 2.6075994007466215e+03, /* 0x40a45f32 0xe4a797e0 */
+t06 = 1.0430393632420044e+04, /* 0x40c45f32 0x628c115e */
+t07 = 4.1720374420664804e+04, /* 0x40e45f0b 0xfb410bc9 */
+t08 = 1.6695720713150888e+05, /* 0x41046169 0xa8349085 */
+t09 = 6.6429163117898861e+05, /* 0x412445c7 0x4329e474 */
+t10 = 2.7802499382503941e+06, /* 0x4145362c 0xf81896c3 */
+t11 = 7.9185101944778729e+06, /* 0x415e34eb 0x8c725352 */
+t12 = 9.3691291294289947e+07, /* 0x41965676 0x6d2d5a58 */
+t13 = -5.0585651903137898e+08, /* 0xc1be26c2 0x07080874 */
+t14 = 6.8772398519624548e+09, /* 0x41f99ea5 0xa2bf6637 */
+t15 = -3.3094464588263161e+10, /* 0xc21ed255 0xd1310d7a */
+t16 = 1.1673794006564838e+11; /* 0x423b2e1f 0x9a61a5fc */
+
+static inline double
+__kernel_tanpi(double x)
+{
+ double hi, lo, t, xhi, xlo;
+ uint32_t hx, lx;
+
+ if (x < 0.25) {
+#if HORNER
+ double x2;
+ /* Horner's method. */
+ x2 = x * x;
+ t = x2 * (x2 * (x2 * (x2 * (x2 * (x2 * (x2 * (x2 * (x2 * (x2
+ * (x2 * (x2 * t16 + t15) + t14) + t13) + t12) + t11)
+ + t10) + t09) + t08) + t07) + t06) + t05) + t04;
+#else
+ double a, b, c, d, x2, x4, x6;
+ /* Sort of Estrin's method. */
+ x2 = x * x;
+ x4 = x2 * x2;
+ x6 = x4 * x2;
+ a = (t16 * x4 + t15 * x2 + t14) * x6;
+ b = (t13 * x4 + t12 * x2 + t11);
+ c = (t10 * x4 + t09 * x2 + t08) * x6;
+ d = (t07 * x4 + t06 * x2 + t05);
+ t = (a + b) * x6 * (x4 * x4) + (c + d) * x2 + t04;
+#endif
+
+ EXTRACT_WORDS(hx, lx, x);
+ INSERT_WORDS(xhi, hx, 0);
+ xlo = x - xhi;
+ xlo *= (xlo + xhi + xhi);
+ xhi *= xhi;
+
+ t = t02lo + x2 * (x2 * t + t03) + t02;
+ t = t01lo + xlo * t + xhi * t + t01;
+ t = t00lo + xlo * t + xhi * t + t00;
+ return (t * x);
+ } else if (x > 0.25) {
+ x = 0.5 - x;
+ t = __kernel_cospi(x) / __kernel_sinpi(x);
+ } else
+ t = 1;
+ return (t);
+}
+
+static inline double
+__compute_tanpi(double x)
+{
+
+ return (x < 0.5 ? __kernel_tanpi(x) : -__kernel_tanpi(1 - x));
+}
+
+double
+tanpi(double x)
+{
+ volatile static const double vzero = 0;
+ double ax;
+ uint32_t hx, ix, j0, lx;
+
+ EXTRACT_WORDS(hx, lx, x);
+ ix = hx & 0x7fffffff;
+ INSERT_WORDS(ax, ix, lx);
+
+ if (ix < 0x3ff00000) { /* |x| < 1 */
+ if (ix < 0x3e200000) { /* |x| < 0x1p-29 */
+ if (x == 0)
+ return (x);
+ INSERT_WORDS(ax, hx, 0);
+ x -= ax;
+ return (pilo * x + pihi * x + pilo * ax + pihi * ax);
+ }
+ if (ix == 0x3fe00000 && !lx)
+ return ((x - x) / (x - x));
+ ax = __compute_tanpi(ax);
+ return ((hx & 0x80000000) ? -ax : ax);
+ }
+
+ if (ix < 0x43300000) { /* 1 <= |x| < 0x1p52 */
+ /* Determine integer part of ax. */
+ j0 = ((ix >> 20) & 0x7ff) - 0x3ff;
+ if (j0 < 20) {
+ ix &= ~(0x000fffff >> j0);
+ lx = 0;
+ } else {
+ lx &= ~(((uint32_t)(0xffffffff)) >> (j0 - 20));
+ }
+ INSERT_WORDS(x,ix,lx);
+
+ ax -= x;
+
+ if (ax == 0.5)
+ return ((x - x) / (x - x));
+
+ ax = ax == 0 ? 0 : __compute_tanpi(ax);
+ return ((hx & 0x80000000) ? -ax : ax);
+ }
+
+ /* x = +-inf or nan. */
+ if (ix >= 0x7f800000)
+ return (vzero / vzero);
+
+ /*
+ * |x| >= 0x1p52 is always an integer, so return +-0.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID?
+ */
+ if (ax + 1 > 1)
+ ax = copysign(0, x);
+ return (ax);
+}
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(tanpi, tanpil);
+#endif
Property changes on: lib/msun/src/s_tanpi.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: lib/msun/src/s_tanpif.c
===================================================================
--- lib/msun/src/s_tanpif.c (nonexistent)
+++ lib/msun/src/s_tanpif.c (working copy)
@@ -0,0 +1,141 @@
+/*-
+ * Copyright (c) 2017 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 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.
+ */
+
+/*
+ * See ../src/s_tanpi.c for implementation details.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_cospif.c"
+#include "k_sinpif.c"
+
+static const float pihi = 3.14160156e+00f; /* 0x40491000 */
+static const float pilo = -8.90890988e-06f; /* 0xb715777a */
+
+static const float
+t0 = 3.14159274e+00f, /* 0x40490fdb */
+t0lo = -8.71231194e-08f, /* 0xb3bb1871 */
+t1 = 1.03354244e+01f, /* 0x41255de6 */
+t1lo = 3.83117083e-07f, /* 0x34cdaf36 */
+t2 = 4.08029366e+01f, /* 0x42233635 */
+t2lo = -1.28256147e-07f, /* 0xb409b6c8 */
+t3 = 1.62950455e+02f, /* 0x4322f351 */
+t3lo = 4.45962769e-06f, /* 0x3695a3e9 */
+t4 = 6.55820984e+02f, /* 0x4423f48b */
+t5 = 2.43586987e+03f, /* 0x45183deb */
+t6 = 1.47717539e+04f, /* 0x4666cf04 */
+t7 = -1.96741250e+04f, /* 0xc699b440 */
+t8 = 5.87398688e+05f; /* 0x490f686b */
+
+static inline float
+__kernel_tanpif(float x)
+{
+ float hi, lo, t, x2, xhi, xlo;
+ uint32_t ix;
+
+ if (x < 0.25f) {
+ x2 = x * x;
+ t = t3lo + x2 * (x2 * (x2 * (x2 * (x2 * t8 + t7) + t6) + t5)
+ + t4) + t3;
+
+ GET_FLOAT_WORD(ix, x);
+ SET_FLOAT_WORD(xhi, (ix >> 14) << 14);
+ xlo = x - xhi;
+ xlo *= (xlo + xhi + xhi);
+ xhi *= xhi;
+
+ t = t2lo + xlo * t + xhi * t + t2;
+ t = t1lo + xlo * t + xhi * t + t1;
+ t = t0lo + xlo * t + xhi * t + t0;
+ t *= x;
+ } else if (x > 0.25f) {
+ x = 0.5f - x;
+ t = __kernel_cospif(x) / __kernel_sinpif(x);
+ } else
+ t = 1;
+ return (t);
+}
+
+static inline float
+__compute_tanpif(float x)
+{
+
+ return (x < 0.5f ? __kernel_tanpif(x) : -__kernel_tanpif(1 - x));
+}
+
+float
+tanpif(float x)
+{
+ volatile static const float vzero = 0;
+ float ax;
+ uint32_t hx, ix, j0;
+
+ GET_FLOAT_WORD(hx, x);
+ ix = hx & 0x7fffffff;
+ SET_FLOAT_WORD(ax, ix);
+
+ if (ix < 0x3f800000) { /* |x| < 1 */
+ if (ix < 0x38800000) { /* |x| < 0x1p-14 */
+ if (x == 0)
+ return (x);
+ SET_FLOAT_WORD(ax, (hx >> 13) << 13);
+ x -= ax;
+ return (pilo * x + pihi * x + pilo * ax + pihi * ax);
+ }
+ if (ix == 0x3f000000)
+ return ((x - x) / (x - x));
+ ax = __compute_tanpif(ax);
+ return ((hx & 0x80000000) ? -ax : ax);
+ }
+
+ if (ix < 0x4b000000) { /* 1 <= |x| < 0x1p23 */
+ /* Determine integer part of ax. */
+ j0 = ((ix >> 23) & 0xff) - 0x7f;
+ ix &= ~(0x007fffff >> j0);
+ SET_FLOAT_WORD(x, ix);
+
+ ax -= x;
+
+ if (ax == 0.5f)
+ return ((x - x) / (x - x));
+
+ ax = ax == 0 ? 0 : __compute_tanpif(ax);
+ return ((hx & 0x80000000) ? -ax : ax);
+ }
+
+ /* x = +-inf or nan. */
+ if (ix >= 0x7f800000)
+ return (vzero / vzero);
+
+ /*
+ * |x| >= 0x1p23 is always an integer, so return +-0.
+ * FIXME: should this raise FE_INEXACT or FE_INVALID.
+ */
+ if (ax + 1 > 1)
+ ax = copysignf(0, x);
+ return (ax);
+}
Property changes on: lib/msun/src/s_tanpif.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
More information about the freebsd-numerics
mailing list