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

📄 e_j0.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_j0.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_j0(x), __ieee754_y0(x) * Bessel function of the first and second kinds of order zero. * Method -- j0(x): *	1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ... *	2. Reduce x to |x| since j0(x)=j0(-x),  and *	   for x in (0,2) *		j0(x) = 1-z/4+ z^2*R0/S0,  where z = x*x; *	   (precision:  |j0-1+z/4-z^2R0/S0 |<2**-63.67 ) *	   for x in (2,inf) * 		j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0)) * 	   where x0 = x-pi/4. It is better to compute sin(x0),cos(x0) *	   as follow: *		cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4) *			= 1/sqrt(2) * (cos(x) + sin(x)) *		sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/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 *		j0(nan)= nan *		j0(0) = 1 *		j0(inf) = 0 *		 * Method -- y0(x): *	1. For x<2. *	   Since  *		y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...) *	   therefore y0(x)-2/pi*j0(x)*ln(x) is an even function. *	   We use the following function to approximate y0, *		y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2 *	   where  *		U(z) = u00 + u01*z + ... + u06*z^6 *		V(z) = 1  + v01*z + ... + v04*z^4 *	   with absolute approximation error bounded by 2**-72. *	   Note: For tiny x, U/V = u0 and j0(x)~1, hence *		y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27) *	2. For x>=2. * 		y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0)) * 	   where x0 = x-pi/4. It is better to compute sin(x0),cos(x0) *	   by the method mentioned above. *	3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0. */#include "fdlibm.h"#ifdef __STDC__static double pzero(double), qzero(double);#elsestatic double pzero(), qzero();#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.00] */R02  =  1.56249999999999947958e-02, /* 0x3F8FFFFF, 0xFFFFFFFD */R03  = -1.89979294238854721751e-04, /* 0xBF28E6A5, 0xB61AC6E9 */R04  =  1.82954049532700665670e-06, /* 0x3EBEB1D1, 0x0C503919 */R05  = -4.61832688532103189199e-09, /* 0xBE33D5E7, 0x73D63FCE */S01  =  1.56191029464890010492e-02, /* 0x3F8FFCE8, 0x82C8C2A4 */S02  =  1.16926784663337450260e-04, /* 0x3F1EA6D2, 0xDD57DBF4 */S03  =  5.13546550207318111446e-07, /* 0x3EA13B54, 0xCE84D5A9 */S04  =  1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */static double zero = 0.0;#ifdef __STDC__	double __ieee754_j0(double x) #else	double __ieee754_j0(x) 	double x;#endif{        fd_twoints un;	double z, s,c,ss,cc,r,u,v;	int hx,ix;        un.d = x;	hx = __HI(un);	ix = hx&0x7fffffff;	if(ix>=0x7ff00000) return one/(x*x);	x = fd_fabs(x);	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;		}	/*	 * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)	 * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)	 */		if(ix>0x48000000) z = (invsqrtpi*cc)/fd_sqrt(x);		else {		    u = pzero(x); v = qzero(x);		    z = invsqrtpi*(u*cc-v*ss)/fd_sqrt(x);		}		return z;	}	if(ix<0x3f200000) {	/* |x| < 2**-13 */	    if(really_big+x>one) {	/* raise inexact if x != 0 */	        if(ix<0x3e400000) return one;	/* |x|<2**-27 */	        else 	      return one - 0.25*x*x;	    }	}	z = x*x;	r =  z*(R02+z*(R03+z*(R04+z*R05)));	s =  one+z*(S01+z*(S02+z*(S03+z*S04)));	if(ix < 0x3FF00000) {	/* |x| < 1.00 */	    return one + z*(-0.25+(r/s));	} else {	    u = 0.5*x;	    return((one+u)*(one-u)+z*(r/s));	}}#ifdef __STDC__static const double#elsestatic double#endifu00  = -7.38042951086872317523e-02, /* 0xBFB2E4D6, 0x99CBD01F */u01  =  1.76666452509181115538e-01, /* 0x3FC69D01, 0x9DE9E3FC */u02  = -1.38185671945596898896e-02, /* 0xBF8C4CE8, 0xB16CFA97 */u03  =  3.47453432093683650238e-04, /* 0x3F36C54D, 0x20B29B6B */u04  = -3.81407053724364161125e-06, /* 0xBECFFEA7, 0x73D25CAD */u05  =  1.95590137035022920206e-08, /* 0x3E550057, 0x3B4EABD4 */u06  = -3.98205194132103398453e-11, /* 0xBDC5E43D, 0x693FB3C8 */v01  =  1.27304834834123699328e-02, /* 0x3F8A1270, 0x91C9C71A */v02  =  7.60068627350353253702e-05, /* 0x3F13ECBB, 0xF578C6C1 */v03  =  2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */v04  =  4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */#ifdef __STDC__	double __ieee754_y0(double x) #else	double __ieee754_y0(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);    /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(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 */        /* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))         * where x0 = x-pi/4         *      Better formula:         *              cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)         *                      =  1/sqrt(2) * (sin(x) + cos(x))         *              sin(x0) = 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.         */                s = fd_sin(x);                c = fd_cos(x);                ss = s-c;                cc = s+c;	/*	 * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)	 * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)	 */                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;                }                if(ix>0x48000000) z = (invsqrtpi*ss)/fd_sqrt(x);                else {                    u = pzero(x); v = qzero(x);                    z = invsqrtpi*(u*ss+v*cc)/fd_sqrt(x);                }                return z;	}	if(ix<=0x3e400000) {	/* x < 2**-27 */	    return(u00 + tpi*__ieee754_log(x));	}	z = x*x;	u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));	v = one+z*(v01+z*(v02+z*(v03+z*v04)));	return(u/v + tpi*(__ieee754_j0(x)*__ieee754_log(x)));}/* The asymptotic expansions of pzero is *	1 - 9/128 s^2 + 11025/98304 s^4 - ...,	where s = 1/x. * For x >= 2, We approximate pzero by * 	pzero(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

⌨️ 快捷键说明

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