Deleted Added
full compact
s_tanl.c (176360) s_tanl.c (221234)
1/*-
2 * Copyright (c) 2007 Steven G. Kargl
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2007 Steven G. Kargl
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/lib/msun/src/s_tanl.c 176360 2008-02-17 07:33:12Z das $");
28__FBSDID("$FreeBSD: head/lib/msun/src/s_tanl.c 221234 2011-04-29 23:13:43Z kargl $");
29
30/*
29
30/*
31 * Compute tan(x) for x where x is reduced to y = x - k * pi / 2.
32 * Limited testing on pseudorandom numbers drawn within [0:4e8] shows
33 * an accuracy of <= 1.5 ULP where 247024 values of x out of 40 million
34 * possibles resulted in tan(x) that exceeded 0.5 ULP (ie., 0.6%).
35 */
36
37#include <float.h>
38
39#include "math.h"
31 * Limited testing on pseudorandom numbers drawn within [0:4e8] shows
32 * an accuracy of <= 1.5 ULP where 247024 values of x out of 40 million
33 * possibles resulted in tan(x) that exceeded 0.5 ULP (ie., 0.6%).
34 */
35
36#include <float.h>
37
38#include "math.h"
39#define INLINE_REM_PIO2L
40#include "math_private.h"
40#include "math_private.h"
41#include "fpmath.h"
42
43#if LDBL_MANT_DIG == 64
41#if LDBL_MANT_DIG == 64
44#define NX 3
45#define PREC 2
42#include "../ld80/e_rem_pio2l.h"
46#elif LDBL_MANT_DIG == 113
43#elif LDBL_MANT_DIG == 113
47#define NX 5
48#define PREC 3
44#include "../ld128/e_rem_pio2l.h"
49#else
50#error "Unsupported long double format"
51#endif
52
45#else
46#error "Unsupported long double format"
47#endif
48
53static const long double two24 = 1.67772160000000000000e+07L;
54
55long double
56tanl(long double x)
57{
58 union IEEEl2bits z;
49long double
50tanl(long double x)
51{
52 union IEEEl2bits z;
59 int i, e0, s;
60 double xd[NX], yd[PREC];
53 int e0, s;
54 long double y[2];
61 long double hi, lo;
62
63 z.e = x;
64 s = z.bits.sign;
65 z.bits.sign = 0;
66
67 /* If x = +-0 or x is subnormal, then tan(x) = x. */
68 if (z.bits.exp == 0)

--- 4 unchanged lines hidden (view full) ---

73 return ((x - x) / (x - x));
74
75 /* Optimize the case where x is already within range. */
76 if (z.e < M_PI_4) {
77 hi = __kernel_tanl(z.e, 0, 0);
78 return (s ? -hi : hi);
79 }
80
55 long double hi, lo;
56
57 z.e = x;
58 s = z.bits.sign;
59 z.bits.sign = 0;
60
61 /* If x = +-0 or x is subnormal, then tan(x) = x. */
62 if (z.bits.exp == 0)

--- 4 unchanged lines hidden (view full) ---

67 return ((x - x) / (x - x));
68
69 /* Optimize the case where x is already within range. */
70 if (z.e < M_PI_4) {
71 hi = __kernel_tanl(z.e, 0, 0);
72 return (s ? -hi : hi);
73 }
74
81 /* Split z.e into a 24-bit representation. */
82 e0 = ilogbl(z.e) - 23;
83 z.e = scalbnl(z.e, -e0);
84 for (i = 0; i < NX; i++) {
85 xd[i] = (double)((int32_t)z.e);
86 z.e = (z.e - xd[i]) * two24;
87 }
88
89 /* yd contains the pieces of xd rem pi/2 such that |yd| < pi/4. */
90 e0 = __kernel_rem_pio2(xd, yd, e0, NX, PREC);
75 e0 = __ieee754_rem_pio2l(x, y);
76 hi = y[0];
77 lo = y[1];
91
78
92#if PREC == 2
93 hi = (long double)yd[0] + yd[1];
94 lo = yd[1] - (hi - yd[0]);
95#else /* PREC == 3 */
96 long double t;
97 t = (long double)yd[2] + yd[1];
98 hi = t + yd[0];
99 lo = yd[0] - (hi - t);
100#endif
101
102 switch (e0 & 3) {
103 case 0:
104 case 2:
105 hi = __kernel_tanl(hi, lo, 0);
106 break;
107 case 1:
108 case 3:
109 hi = __kernel_tanl(hi, lo, 1);
110 break;
111 }
112
79 switch (e0 & 3) {
80 case 0:
81 case 2:
82 hi = __kernel_tanl(hi, lo, 0);
83 break;
84 case 1:
85 case 3:
86 hi = __kernel_tanl(hi, lo, 1);
87 break;
88 }
89
113 return (s ? -hi : hi);
90 return (hi);
114}
91}