Index: lib/msun/Makefile =================================================================== --- lib/msun/Makefile (revision 318383) +++ 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 Index: lib/msun/Symbol.map =================================================================== --- lib/msun/Symbol.map (revision 318383) +++ 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,41 @@ +/*- + * 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 inline long double +__kernel_cospil(long double x) +{ + long double hi, lo; + hi = (double)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + return (__kernel_cosl(hi, lo)); +} 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,41 @@ +/*- + * 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 inline long double +__kernel_sinpil(long double x) +{ + long double hi, lo; + hi = (double)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + return (__kernel_sinl(hi, lo, 1)); +} 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,109 @@ +/*- + * 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" + +static const long double +pihi = 3.14159265358979322702026593105983920e+00L, +pilo = 1.14423774522196636802434264184180742e-17L; + +#include "k_cospil.c" +#include "k_sinpil.c" + +long double +cospil(long double x) +{ + volatile static const double vzero = 0; + long double ax, c, xf; + uint32_t ix; + + ax = fabsl(x); + + if (ax < 1) { + if (ax < 0.25) { + if (ax < 0x1p-60) { + if ((int)x == 0) + return (1); + } + return (__kernel_cospil(ax)); + } + + if (ax < 0.5) + c = __kernel_sinpil(0.5 - ax); + else if (ax < 0.75) { + if (ax == 0.5) + return (0); + c = -__kernel_sinpil(ax - 0.5); + } else + c = -__kernel_cospil(1 - ax); + return (c); + } + + if (ax < 0x1p112) { + + xf = floorl(ax); + + ax -= xf; + + if (x < 0.5) { + if (x < 0.25) + c = ax == 0 ? 1 : __kernel_cospil(ax); + else + c = __kernel_sinpil(0.5 - ax); + } else { + if (x < 0.75) { + if (ax == 0.5) + return (0); + c = -__kernel_sinpil(ax - 0.5); + } else + c = -__kernel_cospil(1 - ax); + } + + if (xf > 0x1p50) xf -= 0x1p50; + if (xf > 0x1p30) xf -= 0x1p30; + ix = (uint32_t)xf; + return (ix & 1 ? -c : c); + } + + if (isinf(x) || isnan(x)) + return (vzero / vzero); + + /* + * |x| >= 0x1p112 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/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,117 @@ +/*- + * 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" + +static const long double +pihi = 3.14159265358979322702026593105983920e+00L, +pilo = 1.14423774522196636802434264184180742e-17L; + +#include "k_cospil.c" +#include "k_sinpil.c" + +long double +sinpil(long double x) +{ + volatile static const double vzero = 0; + long double ax, s, xf, xhi, xlo; + uint32_t ix; + + ax = fabsl(x); + + if (ax < 1) { + if (ax < 0.25) { + if (ax < 0x1p-60) { + if (x == 0) + return (x); + ax = (double)x; + x -= ax; + s = pilo * x + pihi * x + pilo * ax + + pihi * ax; + return (s); + } + + s = __kernel_sinpil(ax); + return (copysignl(s, x)); + } + + if (ax < 0.5) + s = __kernel_cospil(0.5 - ax); + else if (ax < 0.75) + s = __kernel_cospil(ax - 0.5); + else + s = __kernel_sinpil(1 - ax); + return (copysignl(s, x)); + } + + if (ax < 0x1p112) { + + xf = floorl(ax); + + ax -= xf; + + if (ax == 0) { + s = 0; + } else { + if (ax < 0.5) { + if (ax <= 0.25) + s = __kernel_sinpil(ax); + else + s = __kernel_cospil(0.5 - ax); + } else { + if (ax < 0.75) + s = __kernel_cospil(ax - 0.5); + else + s = __kernel_sinpil(1 - ax); + } + + if (xf > 0x1p50) xf -= 0x1p50; + if (xf > 0x1p30) xf -= 0x1p30; + ix = (uint32_t)xf; + if (ix & 1) s = -s; + } + return (copysignl(s, x)); + } + + if (isinf(x) || isnan(x)) + return (vzero / vzero); + + /* + * |x| >= 0x1p112 is always an integer, so return +-0. + * FIXME: should this raise FE_INEXACT or FE_INVALID. + */ + if (ax + 1 > 1) + ax = copysignl(0, x); + return (ax); +} 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,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_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, +pilo = 1.14423774522196636802434264184180742e-17L; + +static inline long double +__kernel_tanpi(long double x) +{ + long double hi, lo, t; + + if (x < 0.25) { + hi = (double)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + t = __kernel_tanl(hi, lo, -1); + } else if (x > 0.25) { + x = 0.5 - x; + hi = (double)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + t = - __kernel_tanl(hi, lo, 1); + } else + t = 1; + + return (t); +} + +long double +tanpil(long double x) +{ + volatile static const double vzero = 0; + long double ax, xf; + uint32_t ix; + + ax = fabsl(ax); + + if (ax < 1) { + if (ax < 0.5) { + if (ax < 0x1p-60) { + if (x == 0) + return (x); + ax = (double)x; + x -= ax; + t = pilo * x + pihi * x + pilo * ax + + pihi * ax; + return (t); + } + t = __kernel_tanpil(ax); + } else if (ax == 0.5) + return ((ax - ax) / (ax - ax)); + else + t = -__kernel_tanpil(1 - ax); + return (copysignl(t, x)); + } + + if (ix < 0x1p112) { + + xf = floorl(ax); + + ax -= xf; + + if (ax < 0.5) + t = ax == 0 ? 0 : __kernel_tanpil(ax); + else if (ax == 0.5) + return ((ax - ax) / (ax - ax)); + else + t = -__kernel_tanpil(1 - ax); + return (copysignl(t, x)); + } + + /* x = +-inf or nan. */ + if (isinf(x) || isnan(x)) + return (vzero / vzero); + + /* + * |x| >= 0x1p53 is always an integer, so return +-0. + * FIXME: should this raise FE_INEXACT or FE_INVALID. + */ + if (ax + 1 > 1) + ax = copysignl(0, x); + return (ax); +} 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,41 @@ +/*- + * 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 inline long double +__kernel_cospil(long double x) +{ + long double hi, lo; + hi = (float)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + return (__kernel_cosl(hi, lo)); +} 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,41 @@ +/*- + * 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 inline long double +__kernel_sinpil(long double x) +{ + long double hi, lo; + hi = (float)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + return (__kernel_sinl(hi, lo, 1)); +} 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,129 @@ +/*- + * 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 +#endif +#include + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +static const double +pihi = 3.1415926814079285e+00, /* 0x400921fb 0x58000000 */ +pilo =-2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */ + +#include "k_cospil.c" +#include "k_sinpil.c" + +long double +cospil(long double x) +{ + volatile static const double vzero = 0; + long double ax, c; + 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 < 0x3ffd) { /* |x| < 0.25 */ + if (ix < 0x3fdd) { /* |x| < 0x1p-34 */ + if ((int)x == 0) + RETURNI(1); + } + RETURNI(__kernel_cospil(ax)); + } + + if (ix < 0x3ffe) /* |x| < 0.5 */ + c = __kernel_sinpil(0.5 - ax); + else if (lx < 0xc000000000000000ull) { /* |x| < 0.75 */ + if (ax == 0.5) + RETURNI(0); + c = -__kernel_sinpil(ax - 0.5); + } else + c = -__kernel_cospil(1 - ax); + RETURNI(c); + } + + 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; + EXTRACT_LDBL80_WORDS(ix, lx, ax); + + if (ix < 0x3ffe) { /* |x| < 0.5 */ + if (ix < 0x3ffd) /* |x| < 0.25 */ + c = ix == 0 ? 1 : __kernel_cospil(ax); + else + c = __kernel_sinpil(0.5 - ax); + + } else { + if (lx < 0xc000000000000000ull) { /* |x| < 0.75 */ + if (ax == 0.5) + RETURNI(0); + c = -__kernel_sinpil(ax - 0.5); + } else + c = -__kernel_cospil(1 - ax); + } + + if (j0 > 40) x -= 0x1p40; + if (j0 > 30) x -= 0x1p30; + j0 = (uint32_t)x; + + RETURNI(j0 & 1 ? -c : c); + } + + 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; + RETURNI(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,136 @@ +/*- + * 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 +#endif +#include + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +static const double +pihi = 3.1415926814079285e+00, /* 0x400921fb 0x58000000 */ +pilo =-2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */ + +#include "k_cospil.c" +#include "k_sinpil.c" + +long double +sinpil(long double x) +{ + volatile static const double vzero = 0; + long double ax, s; + 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 < 0x3ffd) { /* |x| < 0.25 */ + if (ix < 0x3fdd) { /* |x| < 0x1p-34 */ + if (x == 0) + RETURNI(x); + ax = (float)x; + x -= ax; + s = pilo * x + pihi * x + pilo * ax + + pihi * ax; + RETURNI(s); + } + s = __kernel_sinpil(ax); + RETURNI((hx & 0x8000) ? -s : s); + } + + if (ix < 0x3ffe) /* |x| < 0.5 */ + s = __kernel_cospil(0.5 - ax); + else if (lx < 0xc000000000000000ull) /* |x| < 0.75 */ + s = __kernel_cospil(ax - 0.5); + else + s = __kernel_sinpil(1 - ax); + RETURNI((hx & 0x8000) ? -s : s); + } + + 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; + EXTRACT_LDBL80_WORDS(ix, lx, ax); + + if (ix == 0) { + s = 0; + } else { + if (ix < 0x3ffe) { /* |x| < 0.5 */ + if (ix < 0x3ffd) /* |x| < 0.25 */ + s = __kernel_sinpil(ax); + else + s = __kernel_cospil(0.5 - ax); + } else { + /* |x| < 0.75 */ + if (lx < 0xc000000000000000ull) + s = __kernel_cospil(ax - 0.5); + else + s = __kernel_sinpil(1 - ax); + } + + if (j0 > 40) x -= 0x1p40; + if (j0 > 30) x -= 0x1p30; + j0 = (uint32_t)x; + if (j0 & 1) s = -s; + } + RETURNI((hx & 0x8000) ? -s : s); + } + + /* 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,139 @@ +/*- + * 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 +#endif +#include + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +static const double +pihi = 3.1415926814079285e+00, /* 0x400921fb 0x58000000 */ +pilo = -2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */ + +static inline long double +__kernel_tanpil(long double x) +{ + long double hi, lo, t; + + if (x < 0.25) { + hi = (float)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + t = __kernel_tanl(hi, lo, -1); + } else if (x > 0.25) { + x = 0.5 - x; + hi = (float)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + t = - __kernel_tanl(hi, lo, 1); + } else + t = 1; + + return (t); +} + +long double +tanpil(long double x) +{ + volatile static const double vzero = 0; + long double ax, t; + 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 < 0x3ffe) { /* |x| < 0.5 */ + if (ix < 0x3fdd) { /* |x| < 0x1p-34 */ + if (x == 0) + RETURNI(x); + ax = (float)x; + x -= ax; + t = pilo * x + pihi * x + pilo * ax + + pihi * ax; + RETURNI(t); + } + t = __kernel_tanpil(ax); + } else if (ax == 0.5) + RETURNI((ax - ax) / (ax - ax)); + else + t = -__kernel_tanpil(1 - ax); + RETURNI((hx & 0x8000) ? -t : t); + } + + 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; + EXTRACT_LDBL80_WORDS(ix, lx, ax); + + if (ix < 0x3ffe) /* |x| < 0.5 */ + t = ax == 0 ? 0 : __kernel_tanpil(ax); + else if (ax == 0.5) + RETURNI((ax - ax) / (ax - ax)); + else + t = -__kernel_tanpil(1 - ax); + RETURNI((hx & 0x8000) ? -t : t); + } + + /* 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 +.\" 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@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 +.\" 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@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 +.\" 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@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,45 @@ +/*- + * 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. + */ + +/* + * The basic kernel for x in [0,0.25]. To exploit the kernel for cos(x), + * the argument to __kernel_cospi() must be multiply by pi. As pi is an + * irrational number, this allows the splitting of pi*x into high and low + * parts. + */ + +static inline double +__kernel_cospi(double x) +{ + double hi, lo; + hi = (float)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + return (__kernel_cos(hi, lo)); +} + 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_sinpi.c =================================================================== --- lib/msun/src/k_sinpi.c (nonexistent) +++ lib/msun/src/k_sinpi.c (working copy) @@ -0,0 +1,44 @@ +/*- + * 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. + */ + +/* + * The basic kernel for x in [0,0.25]. To exploit the kernel for sin(x), + * the argument to __kernel_sinpi() must be multiply by pi. As pi is an + * irrational number, this allows the splitting of pi*x into high and low + * parts. + */ + +static inline double +__kernel_sinpi(double x) +{ + double hi, lo; + hi = (float)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + return (__kernel_sin(hi, lo, 1)); +} 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/math.h =================================================================== --- lib/msun/src/math.h (revision 318383) +++ 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,152 @@ +/*- + * 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 = 2 to 4. + * + * 2. For |x| < 1, argument reduction is not required and sinpi(x) is + * computed by calling a kernel that leverages the kernels for sin(x) + * ans cos(x). See k_sinpi.c and k_cospi.c for details. + * + * 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. Also, note the following identity + * + * 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 an appropriate kernel. + * + * 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" + +static const double +pihi = 3.1415926814079285e+00, /* 0x400921fb 0x58000000 */ +pilo =-2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */ + +#include "k_cospi.c" +#include "k_sinpi.c" + +double +cospi(double x) +{ + volatile static const double vzero = 0; + double ax, c; + 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 < 0x3fd00000) { /* |x| < 0.25 */ + if (ix < 0x3e200000) { /* |x| < 0x1p-29 */ + if ((int)ax == 0) + return (1); + } + return (__kernel_cospi(ax)); + } + + if (ix < 0x3fe00000) /* |x| < 0.5 */ + c = __kernel_sinpi(0.5 - ax); + else if (ix < 0x3fe80000){ /* |x| < 0.75 */ + if (ax == 0.5) + return (0); + c = -__kernel_sinpi(ax - 0.5); + } else + c = -__kernel_cospi(1 - ax); + return (c); + } + + 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; + EXTRACT_WORDS(ix, lx, ax); + + + if (ix < 0x3fe00000) { /* |x| < 0.5 */ + if (ix < 0x3fd00000) /* |x| < 0.25 */ + c = ix == 0 ? 1 : __kernel_cospi(ax); + else + c = __kernel_sinpi(0.5 - ax); + } else { + if (ix < 0x3fe80000) { /* |x| < 0.75 */ + if (ax == 0.5) + return (0); + c = -__kernel_sinpi(ax - 0.5); + } else + c = -__kernel_cospi(1 - ax); + } + + if (j0 > 30) x -= 0x1p30; + j0 = (uint32_t)x; + return (j0 & 1 ? -c : c); + } + + 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,111 @@ +/*- + * 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. + */ +#define INLINE_KERNEL_SINDF +#define INLINE_KERNEL_COSDF + +#include "math.h" +#include "math_private.h" +#include "k_cosf.c" +#include "k_sinf.c" + +#define __kernel_cospif(x) ((float)__kernel_cosdf(M_PI * (x))) +#define __kernel_sinpif(x) ((float)__kernel_sindf(M_PI * (x))) + +float +cospif(float x) +{ + volatile static const float vzero = 0; + float ax, c; + uint32_t ix, j0; + + GET_FLOAT_WORD(ix, x); + ix = ix & 0x7fffffff; + SET_FLOAT_WORD(ax, ix); + + if (ix < 0x3f800000) { /* |x| < 1 */ + if (ix < 0x3e800000) { /* |x| < 0.25 */ + if (ix < 0x38800000) { /* |x| < 0x1p-14 */ + /* Raise inexact iff != 0. */ + if ((int)ax == 0) + return (1); + } + return (__kernel_cospif(ax)); + } + + if (ix < 0x3f000000) /* |x| < 0.5 */ + c = __kernel_sinpif(0.5f - ax); + else if (ix < 0x3f400000) { /* |x| < 0.75 */ + if (ix == 0x3f000000) + return (0); + c = -__kernel_sinpif(ax - 0.5f); + } else + c = -__kernel_cospif(1 - ax); + return (c); + } + + 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; + GET_FLOAT_WORD(ix, ax); + + if (ix < 0x3f000000) { /* |x| < 0.5 */ + if (ix < 0x3e800000) /* |x| < 0.25 */ + c = ix == 0 ? 1 : __kernel_cospif(ax); + else + c = __kernel_sinpif(0.5f - ax); + } else { + if (ix < 0x3f400000) { /* |x| < 0.75 */ + if (ix == 0x3f000000) + return (0); + c = -__kernel_sinpif(ax - 0.5f); + } else + c = -__kernel_cospif(1 - ax); + } + + j0 = (uint32_t)x; + return (j0 & 1 ? -c : c); + } + + /* 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,163 @@ +/*- + * 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 = 2 to 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 calling a kernel that leverages the kernels for sin(x) + * ans cos(x). See k_sinpi.c and k_cospi.c for details. + * + * 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. Also, note the following identity + * + * 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 an appropriate kernel. + * + * 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" + +static const double +pihi = 3.1415926814079285e+00, /* 0x400921fb 0x58000000 */ +pilo =-2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */ + +#include "k_cospi.c" +#include "k_sinpi.c" + +double +sinpi(double x) +{ + volatile static const double vzero = 0; + double ax, s; + 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 < 0x3fd00000) { /* |x| < 0.25 */ + if (ix < 0x3e200000) { /* |x| < 0x1p-29 */ + if (x == 0) + return (x); + INSERT_WORDS(ax, hx, 0); + x -= ax; + s = pilo * x + pihi * x + pilo * ax + + pihi * ax; + return (s); + } + + s = __kernel_sinpi(ax); + return ((hx & 0x80000000) ? -s : s); + } + + if (ix < 0x3fe00000) /* |x| < 0.5 */ + s = __kernel_cospi(0.5 - ax); + else if (ix < 0x3fe80000) /* |x| < 0.75 */ + s = __kernel_cospi(ax - 0.5); + else + s = __kernel_sinpi(1 - ax); + return ((hx & 0x80000000) ? -s : s); + } + + 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; + EXTRACT_WORDS(ix, lx, ax); + + if (ix == 0) + s = 0; + else { + if (ix < 0x3fe00000) { /* |x| < 0.5 */ + if (ix < 0x3fd00000) /* |x| < 0.25 */ + s = __kernel_sinpi(ax); + else + s = __kernel_cospi(0.5 - ax); + } else { + if (ix < 0x3fe80000) /* |x| < 0.75 */ + s = __kernel_cospi(ax - 0.5); + else + s = __kernel_sinpi(1 - ax); + } + + if (j0 > 30) x -= 0x1p30; + j0 = (uint32_t)x; + if (j0 & 1) s = -s; + } + + return ((hx & 0x80000000) ? -s : s); + } + + 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,122 @@ +/*- + * 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. + */ + +#define INLINE_KERNEL_SINDF +#define INLINE_KERNEL_COSDF + +#include "math.h" +#include "math_private.h" +#include "k_cosf.c" +#include "k_sinf.c" + +#define __kernel_cospif(x) ((float)__kernel_cosdf(M_PI * (x))) +#define __kernel_sinpif(x) ((float)__kernel_sindf(M_PI * (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, s; + 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 < 0x3e800000) { /* |x| < 0.25 */ + if (ix < 0x38800000) { /* |x| < 0x1p-14 */ + if (x == 0) + return (x); + SET_FLOAT_WORD(ax, hx & 0xffff0000); + x -= ax; + s = pilo * x + pihi * x + pilo * ax + + pihi * ax; + return (s); + } + + s = __kernel_sinpif(ax); + return ((hx & 0x80000000) ? -s : s); + } + + if (ix < 0x3f000000) /* |x| < 0.5 */ + s = __kernel_cospif(0.5f - ax); + else if (ix < 0x3f400000) /* |x| < 0.75 */ + s = __kernel_cospif(ax - 0.5f); + else + s = __kernel_sinpif(1 - ax); + return ((hx & 0x80000000) ? -s : s); + } + + 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; + GET_FLOAT_WORD(ix, ax); + + if (ix == 0) + s = 0; + else { + if (ix < 0x3f000000) { /* |x| < 0.5 */ + if (ix < 0x3e800000) /* |x| < 0.25 */ + s = __kernel_sinpif(ax); + else + s = __kernel_cospif(0.5f - ax); + } else { + if (ix < 0x3f400000) /* |x| < 0.75 */ + s = __kernel_cospif(ax - 0.5f); + else + s = __kernel_sinpif(1 - ax); + } + + j0 = (uint32_t)x; + s = (j0 & 1) ? -s : s; + } + return ((hx & 0x80000000) ? -s : s); + } + + /* 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,172 @@ +/*- + * 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 = 2 to 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 a direct call to a kernel, which uses the kernel for + * tan(x). See below. + * + * 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. Also, note the following identity + * + * tan(pi*j0) + tan(pi*r) + * tanpi(x) = tan(pi*(j0+r)) = ---------------------------- = tanpi(r) + * 1 - tan(pi*j0) * tan(pi*r) + * + * So, after argument reduction, the kernel is again invoked. + * + * 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. + */ + +#include "math.h" +#include "math_private.h" + +static const double +pihi = 3.1415926814079285e+00, /* 0x400921fb 0x58000000 */ +pilo = -2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */ + +/* + * The kernel for tanpi(x) multiplies x by an 80-bit approximation of + * pi, where the hi and lo parts are used with with kernel for tan(x). + */ +static inline double +__kernel_tanpi(double x) +{ + double hi, lo, t; + + if (x < 0.25) { + hi = (float)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + t = __kernel_tan(hi, lo, 1); + } else if (x > 0.25) { + x = 0.5 - x; + hi = (float)x; + lo = x - hi; + lo = lo * (pilo + pihi) + hi * pilo; + hi *= pihi; + _2sumF(hi, lo); + t = - __kernel_tan(hi, lo, -1); + } else + t = 1; + + return (t); +} + +double +tanpi(double x) +{ + volatile static const double vzero = 0; + double ax, t; + 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 < 0x3fe00000) { /* |x| < 0.5 */ + if (ix < 0x3e200000) { /* |x| < 0x1p-29 */ + if (x == 0) + return (x); + ax = (float)x; + x -= ax; + t = pilo * x + pihi * x + pilo * ax + + pihi * ax; + return (t); + } + t = __kernel_tanpi(ax); + } else if (ax == 0.5) + return ((ax - ax) / (ax - ax)); + else + t = - __kernel_tanpi(1 - ax); + return ((hx & 0x80000000) ? -t : t); + } + + 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; + EXTRACT_WORDS(ix, lx, ax); + + if (ix < 0x3fe00000) /* |x| < 0.5 */ + t = ax == 0 ? 0 : __kernel_tanpi(ax); + else if (ax == 0.5) + return ((ax - ax) / (ax - ax)); + else + t = - __kernel_tanpi(1 - ax); + + return ((hx & 0x80000000) ? -t : t); + } + + /* 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,115 @@ +/*- + * 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. + */ + +#define INLINE_KERNEL_TANDF + +#include "math.h" +#include "math_private.h" +#include "k_tanf.c" + +static const float +pihi = 3.14160156e+00f, /* 0x40491000 */ +pilo = -8.90890988e-06f; /* 0xb715777a */ + +static inline float +__kernel_tanpif(float x) +{ + float t; + + if (x < 0.25f) + t = __kernel_tandf(M_PI * x, 1); + else if (x > 0.25f) + t = -__kernel_tandf(M_PI * (0.5 - x), -1); + else + t = 1; + + return (t); +} + +float +tanpif(float x) +{ + volatile static const float vzero = 0; + float ax, t; + 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 < 0x3f000000) { /* |x| < 0.5 */ + if (ix < 0x38800000) { /* |x| < 0x1p-14 */ + if (ix == 0) + return (x); + SET_FLOAT_WORD(ax, hx & 0xffff0000); + x -= ax; + t = pilo * x + pihi * x + pilo * ax + + pihi * ax; + return (t); + } + t = __kernel_tanpif(ax); + } else if (ix == 0x3f000000) + return ((ax - ax) / (ax - ax)); + else + t = - __kernel_tanpif(1 - ax); + return ((hx & 0x80000000) ? -t : t); + } + + 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; + GET_FLOAT_WORD(ix, ax); + + if (ix < 0x3f000000) /* |x| < 0.5 */ + t = ix == 0 ? 0 : __kernel_tanpif(ax); + else if (ix == 0x3f000000) + return ((ax - ax) / (ax - ax)); + else + t = - __kernel_tanpif(1 - ax); + return ((hx & 0x80000000) ? -t : t); + } + + /* 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