]> Git Repo - uclibc-ng.git/blame - libm/float/ynf.c
Seems we were lacking an acos() implementation
[uclibc-ng.git] / libm / float / ynf.c
CommitLineData
1077fa4d
EA
1/* ynf.c
2 *
3 * Bessel function of second kind of integer order
4 *
5 *
6 *
7 * SYNOPSIS:
8 *
9 * float x, y, ynf();
10 * int n;
11 *
12 * y = ynf( n, x );
13 *
14 *
15 *
16 * DESCRIPTION:
17 *
18 * Returns Bessel function of order n, where n is a
19 * (possibly negative) integer.
20 *
21 * The function is evaluated by forward recurrence on
22 * n, starting with values computed by the routines
23 * y0() and y1().
24 *
25 * If n = 0 or 1 the routine for y0 or y1 is called
26 * directly.
27 *
28 *
29 *
30 * ACCURACY:
31 *
32 *
33 * Absolute error, except relative when y > 1:
34 *
35 * arithmetic domain # trials peak rms
36 * IEEE 0, 30 10000 2.3e-6 3.4e-7
37 *
38 *
39 * ERROR MESSAGES:
40 *
41 * message condition value returned
42 * yn singularity x = 0 MAXNUMF
43 * yn overflow MAXNUMF
44 *
45 * Spot checked against tables for x, n between 0 and 100.
46 *
47 */
48\f
49/*
50Cephes Math Library Release 2.2: June, 1992
51Copyright 1984, 1987, 1992 by Stephen L. Moshier
52Direct inquiries to 30 Frost Street, Cambridge, MA 02140
53*/
54
55#include <math.h>
56extern float MAXNUMF, MAXLOGF;
57
58float y0f(float), y1f(float), logf(float);
59
60float ynf( int nn, float xx )
61{
62float x, an, anm1, anm2, r, xinv;
63int k, n, sign;
64
65x = xx;
66n = nn;
67if( n < 0 )
68 {
69 n = -n;
70 if( (n & 1) == 0 ) /* -1**n */
71 sign = 1;
72 else
73 sign = -1;
74 }
75else
76 sign = 1;
77
78
79if( n == 0 )
80 return( sign * y0f(x) );
81if( n == 1 )
82 return( sign * y1f(x) );
83
84/* test for overflow */
85if( x <= 0.0 )
86 {
87 mtherr( "ynf", SING );
88 return( -MAXNUMF );
89 }
90if( (x < 1.0) || (n > 29) )
91 {
92 an = (float )n;
93 r = an * logf( an/x );
94 if( r > MAXLOGF )
95 {
96 mtherr( "ynf", OVERFLOW );
97 return( -MAXNUMF );
98 }
99 }
100
101/* forward recurrence on n */
102
103anm2 = y0f(x);
104anm1 = y1f(x);
105k = 1;
106r = 2 * k;
107xinv = 1.0/x;
108do
109 {
110 an = r * anm1 * xinv - anm2;
111 anm2 = anm1;
112 anm1 = an;
113 r += 2.0;
114 ++k;
115 }
116while( k < n );
117
118
119return( sign * an );
120}
This page took 0.040151 seconds and 4 git commands to generate.