source: trunk/libs/newlib/src/newlib/libm/math/w_j0.c @ 543

Last change on this file since 543 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 4.0 KB
Line 
1
2/* @(#)w_j0.c 5.1 93/09/24 */
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14/*
15FUNCTION
16<<jN>>, <<jNf>>, <<yN>>, <<yNf>>---Bessel functions
17
18INDEX
19j0
20INDEX
21j0f
22INDEX
23j1
24INDEX
25j1f
26INDEX
27jn
28INDEX
29jnf
30INDEX
31y0
32INDEX
33y0f
34INDEX
35y1
36INDEX
37y1f
38INDEX
39yn
40INDEX
41ynf
42
43SYNOPSIS
44#include <math.h>
45double j0(double <[x]>);
46float j0f(float <[x]>);
47double j1(double <[x]>);
48float j1f(float <[x]>);
49double jn(int <[n]>, double <[x]>);
50float jnf(int <[n]>, float <[x]>);
51double y0(double <[x]>);
52float y0f(float <[x]>);
53double y1(double <[x]>);
54float y1f(float <[x]>);
55double yn(int <[n]>, double <[x]>);
56float ynf(int <[n]>, float <[x]>);
57
58DESCRIPTION
59The Bessel functions are a family of functions that solve the
60differential equation
61@ifnottex
62.  2               2    2
63. x  y'' + xy' + (x  - p )y  = 0
64@end ifnottex
65@tex
66$$x^2{d^2y\over dx^2} + x{dy\over dx} + (x^2-p^2)y = 0$$
67@end tex
68These functions have many applications in engineering and physics.
69
70<<jn>> calculates the Bessel function of the first kind of order
71<[n]>.  <<j0>> and <<j1>> are special cases for order 0 and order
721 respectively.
73
74Similarly, <<yn>> calculates the Bessel function of the second kind of
75order <[n]>, and <<y0>> and <<y1>> are special cases for order 0 and
761.
77
78<<jnf>>, <<j0f>>, <<j1f>>, <<ynf>>, <<y0f>>, and <<y1f>> perform the
79same calculations, but on <<float>> rather than <<double>> values.
80
81RETURNS
82The value of each Bessel function at <[x]> is returned.
83
84PORTABILITY
85None of the Bessel functions are in ANSI C.
86*/
87
88/*
89 * wrapper j0(double x), y0(double x)
90 */
91
92#include "fdlibm.h"
93#include <errno.h>
94
95#ifndef _DOUBLE_IS_32BITS
96
97#ifdef __STDC__
98        double j0(double x)             /* wrapper j0 */
99#else
100        double j0(x)                    /* wrapper j0 */
101        double x;
102#endif
103{
104#ifdef _IEEE_LIBM
105        return __ieee754_j0(x);
106#else
107        struct exception exc;
108        double z = __ieee754_j0(x);
109        if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
110        if(fabs(x)>X_TLOSS) {
111            /* j0(|x|>X_TLOSS) */
112            exc.type = TLOSS;
113            exc.name = "j0";
114            exc.err = 0;
115            exc.arg1 = exc.arg2 = x;
116            exc.retval = 0.0;
117            if (_LIB_VERSION == _POSIX_)
118               errno = ERANGE;
119            else if (!matherr(&exc)) {
120               errno = ERANGE;
121            }       
122            if (exc.err != 0)
123               errno = exc.err;
124            return exc.retval; 
125        } else
126            return z;
127#endif
128}
129
130#ifdef __STDC__
131        double y0(double x)             /* wrapper y0 */
132#else
133        double y0(x)                    /* wrapper y0 */
134        double x;
135#endif
136{
137#ifdef _IEEE_LIBM
138        return __ieee754_y0(x);
139#else
140        double z;
141        struct exception exc;
142        z = __ieee754_y0(x);
143        if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
144        if(x <= 0.0){
145#ifndef HUGE_VAL
146#define HUGE_VAL inf
147            double inf = 0.0;
148
149            SET_HIGH_WORD(inf,0x7ff00000);      /* set inf to infinite */
150#endif
151            /* y0(0) = -inf or y0(x<0) = NaN */
152            exc.type = DOMAIN;  /* should be SING for IEEE y0(0) */
153            exc.name = "y0";
154            exc.err = 0;
155            exc.arg1 = exc.arg2 = x;
156            if (_LIB_VERSION == _SVID_)
157               exc.retval = -HUGE;
158            else
159               exc.retval = -HUGE_VAL;
160            if (_LIB_VERSION == _POSIX_)
161               errno = EDOM;
162            else if (!matherr(&exc)) {
163               errno = EDOM;
164            }
165            if (exc.err != 0)
166               errno = exc.err;
167            return exc.retval; 
168        }
169        if(x>X_TLOSS) {
170            /* y0(x>X_TLOSS) */
171            exc.type = TLOSS;
172            exc.name = "y0";
173            exc.err = 0;
174            exc.arg1 = exc.arg2 = x;
175            exc.retval = 0.0;
176            if (_LIB_VERSION == _POSIX_)
177               errno = ERANGE;
178            else if (!matherr(&exc)) {
179               errno = ERANGE;
180            }       
181            if (exc.err != 0)
182               errno = exc.err;
183            return exc.retval; 
184        } else
185            return z;
186#endif
187}
188
189#endif /* defined(_DOUBLE_IS_32BITS) */
190
191
192
193
194
195
196
Note: See TracBrowser for help on using the repository browser.