POK
/home/jaouen/pok_official/pok/trunk/libpok/libm/jn.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Fri Jan 30 14:41:34 2009 
00015  */
00016 
00017 /* @(#)w_jn.c 5.1 93/09/24 */
00018 /*
00019  * ====================================================
00020  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00021  *
00022  * Developed at SunPro, a Sun Microsystems, Inc. business.
00023  * Permission to use, copy, modify, and distribute this
00024  * software is freely granted, provided that this notice
00025  * is preserved.
00026  * ====================================================
00027  */
00028 
00029 
00030 #ifdef POK_NEEDS_LIBMATH
00031 
00032 /*
00033  * wrapper jn(int n, double x), yn(int n, double x)
00034  * floating point Bessel's function of the 1st and 2nd kind
00035  * of order n
00036  *
00037  * Special cases:
00038  *      y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
00039  *      y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
00040  * Note 2. About jn(n,x), yn(n,x)
00041  *      For n=0, j0(x) is called,
00042  *      for n=1, j1(x) is called,
00043  *      for n<x, forward recursion us used starting
00044  *      from values of j0(x) and j1(x).
00045  *      for n>x, a continued fraction approximation to
00046  *      j(n,x)/j(n-1,x) is evaluated and then backward
00047  *      recursion is used starting from a supposed value
00048  *      for j(n,x). The resulting value of j(0,x) is
00049  *      compared with the actual value to correct the
00050  *      supposed value of j(n,x).
00051  *
00052  *      yn(n,x) is similar in all respects, except
00053  *      that forward recursion is used for all
00054  *      values of n>1.
00055  *
00056  */
00057 
00058 #include <libm.h>
00059 #include "math_private.h"
00060 
00061 double
00062 jn(int n, double x)     /* wrapper jn */
00063 {
00064 #ifdef _IEEE_LIBM
00065         return __ieee754_jn(n,x);
00066 #else
00067         double z;
00068         z = __ieee754_jn(n,x);
00069         if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
00070         if(fabs(x)>X_TLOSS) {
00071             return __kernel_standard((double)n,x,38); /* jn(|x|>X_TLOSS,n) */
00072         } else
00073             return z;
00074 #endif
00075 }
00076 
00077 double
00078 yn(int n, double x)     /* wrapper yn */
00079 {
00080 #ifdef _IEEE_LIBM
00081         return __ieee754_yn(n,x);
00082 #else
00083         double z;
00084         z = __ieee754_yn(n,x);
00085         if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
00086         if(x <= 0.0){
00087                 if(x==0.0)
00088                     /* d= -one/(x-x); */
00089                     return __kernel_standard((double)n,x,12);
00090                 else
00091                     /* d = zero/(x-x); */
00092                     return __kernel_standard((double)n,x,13);
00093         }
00094         if(x>X_TLOSS) {
00095             return __kernel_standard((double)n,x,39); /* yn(x>X_TLOSS,n) */
00096         } else
00097             return z;
00098 #endif
00099 }
00100 
00101 #endif