Mercurial > hg > octave-kai > gnulib-hg
annotate lib/tanl.c @ 15941:83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
* lib/tanl.c (tanl) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New alternative
implementation.
* m4/tanl.m4 (gl_FUNC_TANL): Require gl_LONG_DOUBLE_VS_DOUBLE.
Determine TANL_LIBM according to HAVE_SAME_LONG_DOUBLE_AS_DOUBLE.
* modules/tanl (Depends-on): Add tan. Update conditions.
(configure.ac): Don't compile trigl.c if
HAVE_SAME_LONG_DOUBLE_AS_DOUBLE.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 11 Oct 2011 02:57:05 +0200 |
parents | 094f6cfdb5c3 |
children | 2074f2bf7216 |
rev | line source |
---|---|
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* s_tanl.c -- long double version of s_tan.c. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
2 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 /* @(#)s_tan.c 5.1 93/09/24 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 /* |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 * ==================================================== |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 * Developed at SunPro, a Sun Microsystems, Inc. business. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 * Permission to use, copy, modify, and distribute this |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 * software is freely granted, provided that this notice |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 * is preserved. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 * ==================================================== |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
8186
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
17 #include <config.h> |
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
18 |
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
19 /* Specification. */ |
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
20 #include <math.h> |
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
21 |
15941
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
22 #if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
23 |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
24 long double |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
25 tanl (long double x) |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
26 { |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
27 return tan (x); |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
28 } |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
29 |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
30 #else |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
31 |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 /* tanl(x) |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 * Return tangent function of x. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 * kernel function: |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
36 * __kernel_tanl ... tangent function on [-pi/4,pi/4] |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
37 * __ieee754_rem_pio2l ... argument reduction routine |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 * Method. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 * Let S,C and T denote the sin, cos and tan respectively on |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
41 * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
42 * in [-pi/4 , +pi/4], and let n = k mod 4. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
43 * We have |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 * n sin(x) cos(x) tan(x) |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 * ---------------------------------------------------------- |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
47 * 0 S C T |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
48 * 1 C -S -1/T |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
49 * 2 -S -C T |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
50 * 3 -C S -1/T |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 * ---------------------------------------------------------- |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 * Special cases: |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 * Let trig be any of sin, cos, or tan. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 * trig(+-INF) is NaN, with signals; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 * trig(NaN) is that NaN; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 * Accuracy: |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
59 * TRIG(x) returns trig(x) nearly rounded |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 |
15941
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
62 # include "trigl.h" |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 /* |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 * ==================================================== |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 * Developed at SunPro, a Sun Microsystems, Inc. business. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 * Permission to use, copy, modify, and distribute this |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 * software is freely granted, provided that this notice |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 * is preserved. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 * ==================================================== |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 /* |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 Long double expansions contributed by |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 Stephen L. Moshier <moshier@na-net.ornl.gov> |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 /* __kernel_tanl( x, y, k ) |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 * Input x is assumed to be bounded by ~pi/4 in magnitude. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 * Input y is the tail of x. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 * Input k indicates whether tan (if k=1) or |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 * -1/tan (if k= -1) is returned. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 * Algorithm |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
88 * 1. Since tan(-x) = -tan(x), we need only to consider positive x. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
89 * 2. if x < 2^-57, return x with inexact if x!=0. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
90 * 3. tan(x) is approximated by a rational form x + x^3 / 3 + x^5 R(x^2) |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 * on [0,0.67433]. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 * |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
93 * Note: tan(x+y) = tan(x) + tan'(x)*y |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
94 * ~ tan(x) + (1+x*x)*y |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
95 * Therefore, for better accuracy in computing tan(x+y), let |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
96 * r = x^3 * R(x^2) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
97 * then |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
98 * tan(x+y) = x + (x^3 / 3 + (x^2 *(r+y)+y)) |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 * 4. For x in [0.67433,pi/4], let y = pi/4 - x, then |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
101 * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
102 * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 static const long double |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 pio4hi = 7.8539816339744830961566084581987569936977E-1L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 pio4lo = 2.1679525325309452561992610065108379921906E-35L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 /* tan x = x + x^3 / 3 + x^5 T(x^2)/U(x^2) |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 0 <= x <= 0.6743316650390625 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 Peak relative error 8.0e-36 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 TH = 3.333333333333333333333333333333333333333E-1L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 T0 = -1.813014711743583437742363284336855889393E7L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 T1 = 1.320767960008972224312740075083259247618E6L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 T2 = -2.626775478255838182468651821863299023956E4L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 T3 = 1.764573356488504935415411383687150199315E2L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 T4 = -3.333267763822178690794678978979803526092E-1L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
119 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 U0 = -1.359761033807687578306772463253710042010E8L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 U1 = 6.494370630656893175666729313065113194784E7L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 U2 = -4.180787672237927475505536849168729386782E6L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 U3 = 8.031643765106170040139966622980914621521E4L, |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 U4 = -5.323131271912475695157127875560667378597E2L; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 /* 1.000000000000000000000000000000000000000E0 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 |
12752
73d9dd27dc41
New modules acosl, asinl, atanl, cosl, expl, logl, sinl, sqrtl, tanl.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
128 static long double |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 kernel_tanl (long double x, long double y, int iy) |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 { |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
131 long double z, r, v, w, s, u, u1; |
9923 | 132 int invert = 0, sign; |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 |
8544 | 134 sign = 1; |
135 if (x < 0) | |
136 { | |
137 x = -x; | |
138 y = -y; | |
139 sign = -1; | |
140 } | |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
141 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 if (x < 0.000000000000000006938893903907228377647697925567626953125L) /* x < 2**-57 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 { |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 if ((int) x == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
145 { /* generate inexact */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
146 if (iy == -1 && x == 0.0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
147 return 1.0L / fabs (x); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
148 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
149 return (iy == 1) ? x : -1.0L / x; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
150 } |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 if (x >= 0.6743316650390625) /* |x| >= 0.6743316650390625 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 { |
9923 | 154 invert = 1; |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 z = pio4hi - x; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 w = pio4lo - y; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 x = z + w; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 y = 0.0; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 z = x * x; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 r = T0 + z * (T1 + z * (T2 + z * (T3 + z * T4))); |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
163 v = U0 + z * (U1 + z * (U2 + z * (U3 + z * (U4 + z)))); |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
164 r = r / v; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
165 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 s = z * x; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 r = y + z * (s * r + y); |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
168 r += TH * s; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
169 w = x + r; |
9923 | 170 if (invert) |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
171 { |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
172 v = (long double) iy; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
173 w = (v - 2.0 * (x - (w * w / (w + v) - r))); |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
174 if (sign < 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
175 w = -w; |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
176 return w; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
177 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
178 if (iy == 1) |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
179 return w; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
181 { /* if allow error up to 2 ulp, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
182 simply return -1.0/(x+r) here */ |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
183 /* compute -1.0/(x+r) accurately */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
184 u1 = (double) w; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
185 v = r - (u1 - x); |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
186 z = -1.0 / w; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
187 u = (double) z; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 s = 1.0 + u * u1; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 return u + z * (s + u * v); |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
190 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
191 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
192 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 long double |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
194 tanl (long double x) |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
195 { |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
196 long double y[2], z = 0.0L; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
197 int n; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
198 |
8563
c3d334708928
Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents:
8544
diff
changeset
|
199 /* tanl(NaN) is NaN */ |
c3d334708928
Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents:
8544
diff
changeset
|
200 if (isnanl (x)) |
c3d334708928
Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents:
8544
diff
changeset
|
201 return x; |
c3d334708928
Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents:
8544
diff
changeset
|
202 |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
203 /* |x| ~< pi/4 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
204 if (x >= -0.7853981633974483096156608458198757210492 && |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
205 x <= 0.7853981633974483096156608458198757210492) |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
206 return kernel_tanl (x, z, 1); |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
207 |
8563
c3d334708928
Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents:
8544
diff
changeset
|
208 /* tanl(Inf) is NaN, tanl(0) is 0 */ |
c3d334708928
Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents:
8544
diff
changeset
|
209 else if (x + x == x) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
210 return x - x; /* NaN */ |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
211 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
212 /* argument reduction needed */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
213 else |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
214 { |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
215 n = ieee754_rem_pio2l (x, y); |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
216 /* 1 -- n even, -1 -- n odd */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
217 return kernel_tanl (y[0], y[1], 1 - ((n & 1) << 1)); |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
218 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
219 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
220 |
15941
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
221 #endif |
83c276c24d2a
tanl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
222 |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
223 #if 0 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
224 int |
4652 | 225 main (void) |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
226 { |
13051 | 227 printf ("%.16Lg\n", tanl (0.7853981633974483096156608458198757210492)); |
228 printf ("%.16Lg\n", tanl (-0.7853981633974483096156608458198757210492)); | |
229 printf ("%.16Lg\n", tanl (0.7853981633974483096156608458198757210492 *3)); | |
230 printf ("%.16Lg\n", tanl (-0.7853981633974483096156608458198757210492 *31)); | |
231 printf ("%.16Lg\n", tanl (0.7853981633974483096156608458198757210492 / 2)); | |
232 printf ("%.16Lg\n", tanl (0.7853981633974483096156608458198757210492 * 3/2)); | |
233 printf ("%.16Lg\n", tanl (0.7853981633974483096156608458198757210492 * 5/2)); | |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
234 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
235 #endif |