Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/cosl.c @ 17907:0a1c2535cad9
euidaccess: Fix Android build
* modules/euidaccess (Depends-on): Add fcntl-h to ensure that
AT_EACCESS gets declared.
author | Kevin Cernekee <cernekee@google.com> |
---|---|
date | Wed, 11 Feb 2015 15:22:54 -0800 |
parents | 2074f2bf7216 |
children |
rev | line source |
---|---|
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* s_cosl.c -- long double version of s_sin.c. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
2 * Conversion to 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 /* |
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 * 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
|
8 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 * 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
|
10 * 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
|
11 * 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
|
12 * is preserved. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 * ==================================================== |
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 |
8186
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
16 #include <config.h> |
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
17 |
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
18 /* Specification. */ |
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
19 #include <math.h> |
c115624bf99a
New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents:
4652
diff
changeset
|
20 |
15940
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
21 #if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
22 |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
23 long double |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
24 cosl (long double x) |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
25 { |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
26 return cos (x); |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
27 } |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
28 |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
29 #else |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
30 |
16511 | 31 /* Code based on glibc/sysdeps/ieee754/ldbl-128/s_cosl.c. */ |
32 | |
33 /* cosl(x) | |
34 * Return cosine function of x. | |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 * kernel function: |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
37 * __kernel_sinl ... sine function on [-pi/4,pi/4] |
16511 | 38 * __kernel_cosl ... cosine function on [-pi/4,pi/4] |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
39 * __ieee754_rem_pio2l ... argument reduction routine |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 * Method. |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 * 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
|
43 * [-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
|
44 * 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
|
45 * We have |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 * n sin(x) cos(x) tan(x) |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 * ---------------------------------------------------------- |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
49 * 0 S C T |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
50 * 1 C -S -1/T |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
51 * 2 -S -C T |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
52 * 3 -C S -1/T |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 * ---------------------------------------------------------- |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 * Special cases: |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 * 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
|
57 * trig(+-INF) is NaN, with signals; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 * trig(NaN) is that NaN; |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 * |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 * Accuracy: |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
61 * 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
|
62 */ |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 |
15940
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
64 # include "trigl.h" |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 |
13051 | 66 long double |
67 cosl (long double x) | |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 { |
13051 | 69 long double y[2],z=0.0L; |
70 int n; | |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 |
13051 | 72 /* cosl(NaN) is NaN */ |
73 if (isnanl (x)) | |
74 return x; | |
8563
c3d334708928
Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents:
8186
diff
changeset
|
75 |
13051 | 76 /* |x| ~< pi/4 */ |
77 if (x >= -0.7853981633974483096156608458198757210492 | |
78 && x <= 0.7853981633974483096156608458198757210492) | |
79 return kernel_cosl(x, z); | |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 |
13051 | 81 /* cosl(Inf) is NaN, cosl(0) is 1 */ |
82 else if (x + x == x && x != 0.0) | |
83 return x - x; /* NaN */ | |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 |
13051 | 85 /* argument reduction needed */ |
86 else | |
87 { | |
88 n = ieee754_rem_pio2l (x, y); | |
89 switch (n & 3) | |
90 { | |
91 case 0: | |
92 return kernel_cosl (y[0], y[1]); | |
93 case 1: | |
94 return -kernel_sinl (y[0], y[1], 1); | |
95 case 2: | |
96 return -kernel_cosl (y[0], y[1]); | |
97 default: | |
98 return kernel_sinl (y[0], y[1], 1); | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10667
diff
changeset
|
99 } |
13051 | 100 } |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 |
15940
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
103 #endif |
564c0603a942
cosl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents:
13051
diff
changeset
|
104 |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 #if 0 |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 int |
4652 | 107 main (void) |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 { |
13051 | 109 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492)); |
110 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *29)); | |
111 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *2)); | |
112 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *30)); | |
113 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *4)); | |
114 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *32)); | |
115 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *2/3)); | |
116 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *4/3)); | |
4239
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 } |
b33b8603715c
Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 #endif |