⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e_j1.c

📁 java script test programing source code
💻 C
📖 第 1 页 / 共 2 页
字号:
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Mozilla Communicator client code, released * March 31, 1998. * * The Initial Developer of the Original Code is * Sun Microsystems, Inc. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** *//* @(#)e_j1.c 1.3 95/01/18 *//* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice  * is preserved. * ==================================================== *//* __ieee754_j1(x), __ieee754_y1(x) * Bessel function of the first and second kinds of order zero. * Method -- j1(x): *	1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ... *	2. Reduce x to |x| since j1(x)=-j1(-x),  and *	   for x in (0,2) *		j1(x) = x/2 + x*z*R0/S0,  where z = x*x; *	   (precision:  |j1/x - 1/2 - R0/S0 |<2**-61.51 ) *	   for x in (2,inf) * 		j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1)) * 		y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1)) * 	   where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1) *	   as follow: *		cos(x1) =  cos(x)cos(3pi/4)+sin(x)sin(3pi/4) *			=  1/sqrt(2) * (sin(x) - cos(x)) *		sin(x1) =  sin(x)cos(3pi/4)-cos(x)sin(3pi/4) *			= -1/sqrt(2) * (sin(x) + cos(x)) * 	   (To avoid cancellation, use *		sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) * 	    to compute the worse one.) *	    *	3 Special cases *		j1(nan)= nan *		j1(0) = 0 *		j1(inf) = 0 *		 * Method -- y1(x): *	1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN  *	2. For x<2. *	   Since  *		y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...) *	   therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function. *	   We use the following function to approximate y1, *		y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2 *	   where for x in [0,2] (abs err less than 2**-65.89) *		U(z) = U0[0] + U0[1]*z + ... + U0[4]*z^4 *		V(z) = 1  + v0[0]*z + ... + v0[4]*z^5 *	   Note: For tiny x, 1/x dominate y1 and hence *		y1(tiny) = -2/pi/tiny, (choose tiny<2**-54) *	3. For x>=2. * 		y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1)) * 	   where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1) *	   by method mentioned above. */#include "fdlibm.h"#ifdef __STDC__static double pone(double), qone(double);#elsestatic double pone(), qone();#endif#ifdef __STDC__static const double #elsestatic double #endifreally_big    = 1e300,one	= 1.0,invsqrtpi=  5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */tpi      =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */	/* R0/S0 on [0,2] */r00  = -6.25000000000000000000e-02, /* 0xBFB00000, 0x00000000 */r01  =  1.40705666955189706048e-03, /* 0x3F570D9F, 0x98472C61 */r02  = -1.59955631084035597520e-05, /* 0xBEF0C5C6, 0xBA169668 */r03  =  4.96727999609584448412e-08, /* 0x3E6AAAFA, 0x46CA0BD9 */s01  =  1.91537599538363460805e-02, /* 0x3F939D0B, 0x12637E53 */s02  =  1.85946785588630915560e-04, /* 0x3F285F56, 0xB9CDF664 */s03  =  1.17718464042623683263e-06, /* 0x3EB3BFF8, 0x333F8498 */s04  =  5.04636257076217042715e-09, /* 0x3E35AC88, 0xC97DFF2C */s05  =  1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */static double zero    = 0.0;#ifdef __STDC__	double __ieee754_j1(double x) #else	double __ieee754_j1(x) 	double x;#endif{        fd_twoints un;	double z, s,c,ss,cc,r,u,v,y;	int hx,ix;        un.d = x;	hx = __HI(un);	ix = hx&0x7fffffff;	if(ix>=0x7ff00000) return one/x;	y = fd_fabs(x);	if(ix >= 0x40000000) {	/* |x| >= 2.0 */		s = fd_sin(y);		c = fd_cos(y);		ss = -s-c;		cc = s-c;		if(ix<0x7fe00000) {  /* make sure y+y not overflow */		    z = fd_cos(y+y);		    if ((s*c)>zero) cc = z/ss;		    else 	    ss = z/cc;		}	/*	 * j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)	 * y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)	 */		if(ix>0x48000000) z = (invsqrtpi*cc)/fd_sqrt(y);		else {		    u = pone(y); v = qone(y);		    z = invsqrtpi*(u*cc-v*ss)/fd_sqrt(y);		}		if(hx<0) return -z;		else  	 return  z;	}	if(ix<0x3e400000) {	/* |x|<2**-27 */	    if(really_big+x>one) return 0.5*x;/* inexact if x!=0 necessary */	}	z = x*x;	r =  z*(r00+z*(r01+z*(r02+z*r03)));	s =  one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));	r *= x;	return(x*0.5+r/s);}#ifdef __STDC__static const double U0[5] = {#elsestatic double U0[5] = {#endif -1.96057090646238940668e-01, /* 0xBFC91866, 0x143CBC8A */  5.04438716639811282616e-02, /* 0x3FA9D3C7, 0x76292CD1 */ -1.91256895875763547298e-03, /* 0xBF5F55E5, 0x4844F50F */  2.35252600561610495928e-05, /* 0x3EF8AB03, 0x8FA6B88E */ -9.19099158039878874504e-08, /* 0xBE78AC00, 0x569105B8 */};#ifdef __STDC__static const double V0[5] = {#elsestatic double V0[5] = {#endif  1.99167318236649903973e-02, /* 0x3F94650D, 0x3F4DA9F0 */  2.02552581025135171496e-04, /* 0x3F2A8C89, 0x6C257764 */  1.35608801097516229404e-06, /* 0x3EB6C05A, 0x894E8CA6 */  6.22741452364621501295e-09, /* 0x3E3ABF1D, 0x5BA69A86 */  1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */};#ifdef __STDC__	double __ieee754_y1(double x) #else	double __ieee754_y1(x) 	double x;#endif{        fd_twoints un;	double z, s,c,ss,cc,u,v;	int hx,ix,lx;        un.d = x;        hx = __HI(un);        ix = 0x7fffffff&hx;        lx = __LO(un);    /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */	if(ix>=0x7ff00000) return  one/(x+x*x);         if((ix|lx)==0) return -one/zero;        if(hx<0) return zero/zero;        if(ix >= 0x40000000) {  /* |x| >= 2.0 */                s = fd_sin(x);                c = fd_cos(x);                ss = -s-c;                cc = s-c;                if(ix<0x7fe00000) {  /* make sure x+x not overflow */                    z = fd_cos(x+x);                    if ((s*c)>zero) cc = z/ss;                    else            ss = z/cc;                }        /* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))         * where x0 = x-3pi/4         *      Better formula:         *              cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)         *                      =  1/sqrt(2) * (sin(x) - cos(x))         *              sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)         *                      = -1/sqrt(2) * (cos(x) + sin(x))         * To avoid cancellation, use         *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))         * to compute the worse one.         */                if(ix>0x48000000) z = (invsqrtpi*ss)/fd_sqrt(x);                else {                    u = pone(x); v = qone(x);                    z = invsqrtpi*(u*ss+v*cc)/fd_sqrt(x);                }                return z;        }         if(ix<=0x3c900000) {    /* x < 2**-54 */            return(-tpi/x);        }         z = x*x;        u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));        v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));        return(x*(u/v) + tpi*(__ieee754_j1(x)*__ieee754_log(x)-one/x));}/* For x >= 8, the asymptotic expansions of pone is *	1 + 15/128 s^2 - 4725/2^15 s^4 - ...,	where s = 1/x. * We approximate pone by * 	pone(x) = 1 + (R/S) * where  R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10 * 	  S = 1 + ps0*s^2 + ... + ps4*s^10 * and *	| pone(x)-1-R/S | <= 2  ** ( -60.06) */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -