POK
jn.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Fri Jan 30 14:41:34 2009
15  */
16 
17 /* @(#)w_jn.c 5.1 93/09/24 */
18 /*
19  * ====================================================
20  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
21  *
22  * Developed at SunPro, a Sun Microsystems, Inc. business.
23  * Permission to use, copy, modify, and distribute this
24  * software is freely granted, provided that this notice
25  * is preserved.
26  * ====================================================
27  */
28 
29 
30 #ifdef POK_NEEDS_LIBMATH
31 
32 /*
33  * wrapper jn(int n, double x), yn(int n, double x)
34  * floating point Bessel's function of the 1st and 2nd kind
35  * of order n
36  *
37  * Special cases:
38  * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
39  * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
40  * Note 2. About jn(n,x), yn(n,x)
41  * For n=0, j0(x) is called,
42  * for n=1, j1(x) is called,
43  * for n<x, forward recursion us used starting
44  * from values of j0(x) and j1(x).
45  * for n>x, a continued fraction approximation to
46  * j(n,x)/j(n-1,x) is evaluated and then backward
47  * recursion is used starting from a supposed value
48  * for j(n,x). The resulting value of j(0,x) is
49  * compared with the actual value to correct the
50  * supposed value of j(n,x).
51  *
52  * yn(n,x) is similar in all respects, except
53  * that forward recursion is used for all
54  * values of n>1.
55  *
56  */
57 
58 #include <libm.h>
59 #include "math_private.h"
60 
61 double
62 jn(int n, double x) /* wrapper jn */
63 {
64 #ifdef _IEEE_LIBM
65  return __ieee754_jn(n,x);
66 #else
67  double z;
68  z = __ieee754_jn(n,x);
69  if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
70  if(fabs(x)>X_TLOSS) {
71  return __kernel_standard((double)n,x,38); /* jn(|x|>X_TLOSS,n) */
72  } else
73  return z;
74 #endif
75 }
76 
77 double
78 yn(int n, double x) /* wrapper yn */
79 {
80 #ifdef _IEEE_LIBM
81  return __ieee754_yn(n,x);
82 #else
83  double z;
84  z = __ieee754_yn(n,x);
85  if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
86  if(x <= 0.0){
87  if(x==0.0)
88  /* d= -one/(x-x); */
89  return __kernel_standard((double)n,x,12);
90  else
91  /* d = zero/(x-x); */
92  return __kernel_standard((double)n,x,13);
93  }
94  if(x>X_TLOSS) {
95  return __kernel_standard((double)n,x,39); /* yn(x>X_TLOSS,n) */
96  } else
97  return z;
98 #endif
99 }
100 
101 #endif