source: trunk/libs/newlib/src/newlib/libm/mathfp/w_jn.c @ 543

Last change on this file since 543 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 4.8 KB
Line 
1
2/* @(#)w_jn.c 5.1 93/09/24 */
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14/*
15FUNCTION
16<<jN>>, <<jNf>>, <<yN>>, <<yNf>>---Bessel functions
17
18INDEX
19j0
20INDEX
21j0f
22INDEX
23j1
24INDEX
25j1f
26INDEX
27jn
28INDEX
29jnf
30INDEX
31y0
32INDEX
33y0f
34INDEX
35y1
36INDEX
37y1f
38INDEX
39yn
40INDEX
41ynf
42
43SYNOPSIS
44#include <math.h>
45double j0(double <[x]>);
46float j0f(float <[x]>);
47double j1(double <[x]>);
48float j1f(float <[x]>);
49double jn(int <[n]>, double <[x]>);
50float jnf(int <[n]>, float <[x]>);
51double y0(double <[x]>);
52float y0f(float <[x]>);
53double y1(double <[x]>);
54float y1f(float <[x]>);
55double yn(int <[n]>, double <[x]>);
56float ynf(int <[n]>, float <[x]>);
57
58DESCRIPTION
59The Bessel functions are a family of functions that solve the
60differential equation
61@ifnottex
62.  2               2    2
63. x  y'' + xy' + (x  - p )y  = 0
64@end ifnottex
65@tex
66$$x^2{d^2y\over dx^2} + x{dy\over dx} + (x^2-p^2)y = 0$$
67@end tex
68These functions have many applications in engineering and physics.
69
70<<jn>> calculates the Bessel function of the first kind of order
71<[n]>.  <<j0>> and <<j1>> are special cases for order 0 and order
721 respectively.
73
74Similarly, <<yn>> calculates the Bessel function of the second kind of
75order <[n]>, and <<y0>> and <<y1>> are special cases for order 0 and
761.
77
78<<jnf>>, <<j0f>>, <<j1f>>, <<ynf>>, <<y0f>>, and <<y1f>> perform the
79same calculations, but on <<float>> rather than <<double>> values.
80
81RETURNS
82The value of each Bessel function at <[x]> is returned.
83
84PORTABILITY
85None of the Bessel functions are in ANSI C.
86*/
87
88/*
89 * wrapper jn(int n, double x), yn(int n, double x)
90 * floating point Bessel's function of the 1st and 2nd kind
91 * of order n
92 *         
93 * Special cases:
94 *      y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
95 *      y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
96 * Note 2. About jn(n,x), yn(n,x)
97 *      For n=0, j0(x) is called,
98 *      for n=1, j1(x) is called,
99 *      for n<x, forward recursion us used starting
100 *      from values of j0(x) and j1(x).
101 *      for n>x, a continued fraction approximation to
102 *      j(n,x)/j(n-1,x) is evaluated and then backward
103 *      recursion is used starting from a supposed value
104 *      for j(n,x). The resulting value of j(0,x) is
105 *      compared with the actual value to correct the
106 *      supposed value of j(n,x).
107 *
108 *      yn(n,x) is similar in all respects, except
109 *      that forward recursion is used for all
110 *      values of n>1.
111 *     
112 */
113
114#include "fdlibm.h"
115#include <errno.h>
116
117#ifndef _DOUBLE_IS_32BITS
118
119#ifdef __STDC__
120        double jn(int n, double x)      /* wrapper jn */
121#else
122        double jn(n,x)                  /* wrapper jn */
123        double x; int n;
124#endif
125{
126#ifdef _IEEE_LIBM
127        return jn(n,x);
128#else
129        double z;
130        struct exception exc;
131        z = jn(n,x);
132        if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
133        if(fabs(x)>X_TLOSS) {
134            /* jn(|x|>X_TLOSS) */
135            exc.type = TLOSS;
136            exc.name = "jn";
137            exc.err = 0;
138            exc.arg1 = n;
139            exc.arg2 = x;
140            exc.retval = 0.0;
141            if (_LIB_VERSION == _POSIX_)
142                errno = ERANGE;
143            else if (!matherr(&exc)) {
144               errno = ERANGE;
145            }       
146            if (exc.err != 0)
147               errno = exc.err;
148            return exc.retval; 
149        } else
150            return z;
151#endif
152}
153
154#ifdef __STDC__
155        double yn(int n, double x)      /* wrapper yn */
156#else
157        double yn(n,x)                  /* wrapper yn */
158        double x; int n;
159#endif
160{
161#ifdef _IEEE_LIBM
162        return yn(n,x);
163#else
164        double z;
165        struct exception exc;
166        z = yn(n,x);
167        if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
168        if(x <= 0.0){
169            /* yn(n,0) = -inf or yn(x<0) = NaN */
170#ifndef HUGE_VAL
171#define HUGE_VAL inf
172            double inf = 0.0;
173
174            SET_HIGH_WORD(inf,0x7ff00000);      /* set inf to infinite */
175#endif
176            exc.type = DOMAIN;  /* should be SING for IEEE */
177            exc.name = "yn";
178            exc.err = 0;
179            exc.arg1 = n;
180            exc.arg2 = x;
181            if (_LIB_VERSION == _SVID_)
182                exc.retval = -HUGE;
183            else
184                exc.retval = -HUGE_VAL;
185            if (_LIB_VERSION == _POSIX_)
186                errno = EDOM;
187            else if (!matherr(&exc)) {
188                errno = EDOM;
189            }
190            if (exc.err != 0)
191               errno = exc.err;
192            return exc.retval; 
193        }
194        if(x>X_TLOSS) {
195            /* yn(x>X_TLOSS) */
196            exc.type = TLOSS;
197            exc.name = "yn";
198            exc.err = 0;
199            exc.arg1 = n;
200            exc.arg2 = x;
201            exc.retval = 0.0;
202            if (_LIB_VERSION == _POSIX_)
203                errno = ERANGE;
204            else if (!matherr(&exc)) {
205                errno = ERANGE;
206            }       
207            if (exc.err != 0)
208               errno = exc.err;
209            return exc.retval; 
210        } else
211            return z;
212#endif
213}
214
215#endif /* defined(_DOUBLE_IS_32BITS) */
Note: See TracBrowser for help on using the repository browser.