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

📄 e_j1.c

📁 ecos实时嵌入式操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
//===========================================================================////      e_j1.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_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 "mathincl/fdlibm.h"static double pone(double), qone(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] */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;        double __ieee754_j1(double x) {        double z, s,c,ss,cc,r,u,v,y;        int hx,ix;        hx = CYG_LIBM_HI(x);        ix = hx&0x7fffffff;        if(ix>=0x7ff00000) return one/x;        y = fabs(x);        if(ix >= 0x40000000) {  /* |x| >= 2.0 */                s = sin(y);                c = cos(y);                ss = -s-c;                cc = s-c;                if(ix<0x7fe00000) {  /* make sure y+y not overflow */                    z = 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)/sqrt(y);                else {                    u = pone(y); v = qone(y);                    z = invsqrtpi*(u*cc-v*ss)/sqrt(y);                }                if(hx<0) return -z;                else     return  z;        }        if(ix<0x3e400000) {     /* |x|<2**-27 */            if(huge+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);}static const double U0[5] = { -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 */};static const double V0[5] = {  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 */};        double __ieee754_y1(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);    /* 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 = 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;

⌨️ 快捷键说明

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