📄 e_j0.c
字号:
//===========================================================================//// e_j0.c//// Part of the standard mathematical function library////===========================================================================//####ECOSGPLCOPYRIGHTBEGIN####// -------------------------------------------// This file is part of eCos, the Embedded Configurable Operating System.// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.//// eCos is free software; you can redistribute it and/or modify it under// the terms of the GNU General Public License as published by the Free// Software Foundation; either version 2 or (at your option) any later version.//// eCos is distributed in the hope that it will be useful, but WITHOUT ANY// WARRANTY; without even the implied warranty of MERCHANTABILITY or// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License// for more details.//// You should have received a copy of the GNU General Public License along// with eCos; if not, write to the Free Software Foundation, Inc.,// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.//// As a special exception, if other files instantiate templates or use macros// or inline functions from this file, or you compile this file and link it// with other works to produce a work based on this file, this file does not// by itself cause the resulting work to be covered by the GNU General Public// License. However the source code for this file must still be made available// in accordance with section (3) of the GNU General Public License.//// This exception does not invalidate any other reasons why a work based on// this file might be covered by the GNU General Public License.//// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.// at http://sources.redhat.com/ecos/ecos-license/// -------------------------------------------//####ECOSGPLCOPYRIGHTEND####//===========================================================================//#####DESCRIPTIONBEGIN####//// Author(s): jlarmour// Contributors: jlarmour// Date: 1998-02-13// Purpose: // Description: // Usage: ////####DESCRIPTIONEND####////===========================================================================// CONFIGURATION#include <pkgconf/libm.h> // Configuration header// Include the Math library?#ifdef CYGPKG_LIBM // Derived from code with the following copyright/* @(#)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 "mathincl/fdlibm.h"static double pzero(double), qzero(double);static const double huge = 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; double __ieee754_j0(double x) { double z, s,c,ss,cc,r,u,v; int hx,ix; hx = CYG_LIBM_HI(x); ix = hx&0x7fffffff; if(ix>=0x7ff00000) return one/(x*x); x = fabs(x); if(ix >= 0x40000000) { /* |x| >= 2.0 */ s = sin(x); c = cos(x); ss = s-c; cc = s+c; if(ix<0x7fe00000) { /* make sure x+x not overflow */ z = -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)/sqrt(x); else { u = pzero(x); v = qzero(x); z = invsqrtpi*(u*cc-v*ss)/sqrt(x); } return z; } if(ix<0x3f200000) { /* |x| < 2**-13 */ if(huge+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)); }}static const doubleu00 = -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 */ double __ieee754_y0(double x) { double z, s,c,ss,cc,u,v; int hx,ix,lx; hx = CYG_LIBM_HI(x); ix = 0x7fffffff&hx; lx = CYG_LIBM_LO(x); /* 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))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -