📄 e_j1l.c
字号:
/* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== *//* Long double expansions are Copyright (C) 2001 Stephen L. Moshier <moshier@na-net.ornl.gov> and are incorporated herein by permission of the author. The author reserves the right to distribute this material elsewhere under different copying permissions. These modifications are distributed here under the following terms: This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* __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; * 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 * Note: For tiny x, 1/x dominate y1 and hence * y1(tiny) = -2/pi/tiny * 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 "math.h"#include "math_private.h"#ifdef __STDC__static long double pone (long double), qone (long double);#elsestatic long double pone (), qone ();#endif#ifdef __STDC__static const long double#elsestatic long double#endif huge = 1e4930L, one = 1.0L, invsqrtpi = 5.6418958354775628694807945156077258584405e-1L, tpi = 6.3661977236758134307553505349005744813784e-1L, /* J1(x) = .5 x + x x^2 R(x^2) / S(x^2) 0 <= x <= 2 Peak relative error 4.5e-21 */R[5] = { -9.647406112428107954753770469290757756814E7L, 2.686288565865230690166454005558203955564E6L, -3.689682683905671185891885948692283776081E4L, 2.195031194229176602851429567792676658146E2L, -5.124499848728030297902028238597308971319E-1L,}, S[4] ={ 1.543584977988497274437410333029029035089E9L, 2.133542369567701244002565983150952549520E7L, 1.394077011298227346483732156167414670520E5L, 5.252401789085732428842871556112108446506E2L, /* 1.000000000000000000000000000000000000000E0L, */};#ifdef __STDC__static const long double zero = 0.0;#elsestatic long double zero = 0.0;#endif#ifdef __STDC__long double__ieee754_j1l (long double x)#elselong double__ieee754_j1l (x) long double x;#endif{ long double z, c, r, s, ss, cc, u, v, y; int32_t ix; u_int32_t se, i0, i1; GET_LDOUBLE_WORDS (se, i0, i1, x); ix = se & 0x7fff; if (ix >= 0x7fff) return one / x; y = fabsl (x); if (ix >= 0x4000) { /* |x| >= 2.0 */ __sincosl (y, &s, &c); ss = -s - c; cc = s - c; if (ix < 0x7ffe) { /* make sure y+y not overflow */ z = __cosl (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 > 0x4080) z = (invsqrtpi * cc) / __ieee754_sqrtl (y); else { u = pone (y); v = qone (y); z = invsqrtpi * (u * cc - v * ss) / __ieee754_sqrtl (y); } if (se & 0x8000) return -z; else return z; } if (ix < 0x3fde) /* |x| < 2^-33 */ { if (huge + x > one) return 0.5 * x; /* inexact if x!=0 necessary */ } z = x * x; r = z * (R[0] + z * (R[1]+ z * (R[2] + z * (R[3] + z * R[4])))); s = S[0] + z * (S[1] + z * (S[2] + z * (S[3] + z))); r *= x; return (x * 0.5 + r / s);}/* Y1(x) = 2/pi * (log(x) * j1(x) - 1/x) + x R(x^2) 0 <= x <= 2 Peak relative error 2.3e-23 */#ifdef __STDC__static const long double U0[6] = {#elsestatic long double U0[6] = {#endif -5.908077186259914699178903164682444848615E10L, 1.546219327181478013495975514375773435962E10L, -6.438303331169223128870035584107053228235E8L, 9.708540045657182600665968063824819371216E6L, -6.138043997084355564619377183564196265471E4L, 1.418503228220927321096904291501161800215E2L,};#ifdef __STDC__static const long double V0[5] = {#elsestatic long double V0[5] = {#endif 3.013447341682896694781964795373783679861E11L, 4.669546565705981649470005402243136124523E9L, 3.595056091631351184676890179233695857260E7L, 1.761554028569108722903944659933744317994E5L, 5.668480419646516568875555062047234534863E2L, /* 1.000000000000000000000000000000000000000E0L, */};#ifdef __STDC__long double__ieee754_y1l (long double x)#elselong double__ieee754_y1l (x) long double x;#endif{ long double z, s, c, ss, cc, u, v; int32_t ix; u_int32_t se, i0, i1; GET_LDOUBLE_WORDS (se, i0, i1, x); ix = se & 0x7fff; /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */ if (se & 0x8000) return zero / zero; if (ix >= 0x7fff) return one / (x + x * x); if ((i0 | i1) == 0) return -one / zero; if (ix >= 0x4000) { /* |x| >= 2.0 */ __sincosl (x, &s, &c); ss = -s - c; cc = s - c; if (ix < 0x7fe00000) { /* make sure x+x not overflow */ z = __cosl (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 > 0x4080) z = (invsqrtpi * ss) / __ieee754_sqrtl (x); else { u = pone (x); v = qone (x); z = invsqrtpi * (u * ss + v * cc) / __ieee754_sqrtl (x); } return z; } if (ix <= 0x3fbe) { /* x < 2**-65 */ return (-tpi / x); } z = x * x; u = U0[0] + z * (U0[1] + z * (U0[2] + z * (U0[3] + z * (U0[4] + z * U0[5])))); v = V0[0] + z * (V0[1] + z * (V0[2] + z * (V0[3] + z * (V0[4] + z)))); return (x * (u / v) + tpi * (__ieee754_j1l (x) * __ieee754_logl (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) *//* J1(x) cosX + Y1(x) sinX = sqrt( 2/(pi x)) P1(x) P1(x) = 1 + z^2 R(z^2), z=1/x 8 <= x <= inf (0 <= z <= 0.125) Peak relative error 5.2e-22 */#ifdef __STDC__static const long double pr8[7] = {#elsestatic long double pr8[7] = {#endif 8.402048819032978959298664869941375143163E-9L, 1.813743245316438056192649247507255996036E-6L, 1.260704554112906152344932388588243836276E-4L, 3.439294839869103014614229832700986965110E-3L, 3.576910849712074184504430254290179501209E-2L, 1.131111483254318243139953003461511308672E-1L, 4.480715825681029711521286449131671880953E-2L,};#ifdef __STDC__static const long double ps8[6] = {#elsestatic long double ps8[6] = {#endif 7.169748325574809484893888315707824924354E-8L, 1.556549720596672576431813934184403614817E-5L, 1.094540125521337139209062035774174565882E-3L, 3.060978962596642798560894375281428805840E-2L, 3.374146536087205506032643098619414507024E-1L, 1.253830208588979001991901126393231302559E0L, /* 1.000000000000000000000000000000000000000E0L, */};/* J1(x) cosX + Y1(x) sinX = sqrt( 2/(pi x)) P1(x) P1(x) = 1 + z^2 R(z^2), z=1/x 4.54541015625 <= x <= 8 Peak relative error 7.7e-22 */#ifdef __STDC__static const long double pr5[7] = {#elsestatic long double pr5[7] = {#endif 4.318486887948814529950980396300969247900E-7L, 4.715341880798817230333360497524173929315E-5L,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -