NFFT Logo 3.2.3
bessel_i0.c
1 /*
2  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /* $Id: util.c 3483 2010-04-23 19:02:34Z keiner $ */
20 
21 #include "infft.h"
22 
23 #if defined(NFFT_LDOUBLE)
24  #if LDBL_MANT_DIG > 64
25  /* long double 128 bit wide */
26  static const R P1[] =
27  {
28  K(1.00715709113717408460589579223209941204261347125985390244049122),
29  K(0.244951997023176876020320575838917179801959212259109588711443322),
30  K(0.007157677421552158878119583351756319398653762265084335703499437),
31  K(0.000088638803372684623765617528646130117285577351082745565226135),
32  K(5.86290506716174293160891590037213629006472953235560773267e-7),
33  K(2.345957469650316879673588315314269880856753475545514611e-9),
34  K(6.128655873200031753345017339110506400750029700912053e-12),
35  K(1.0986892011606471142197070904902679807307454250063e-14),
36  K(1.3971139352985872209413265761909675621623302845e-17),
37  K(1.2871864763402201040551492995178709443354555e-20),
38  K(8.691006015934819586402366491436791599814e-24),
39  K(4.309390047550403478410330783891146603e-27),
40  K(1.555612957227921944637472907134242e-30),
41  K(3.9925388022711127965090640127e-34),
42  K(6.9368410036374068977799409e-38),
43  K(7.357454531748581565018e-42),
44  K(3.62204101214442072e-46),
45  };
46  static const R Q1[] =
47  {
48  K(1.000007070784273109528051454385187718969110645914059499666326971665),
49  K(-0.005313926453449002844879821442805584438144938596471790433918964154),
50  K(7.070788418542362565462155969863941136682888242514039780835548e-6),
51  K(-6.26540971437695808708857953483635930152829451235344028056e-9),
52  K(4.145433773149898726789014352388133793941127788810021957e-12),
53  K(-2.175603200497645955857316018087216481968512641548262e-15),
54  K(9.38635995876117135738708302122439402494096616172e-19),
55  K(-3.40237206590514988600833435986797066144532635e-22),
56  K(1.04920116497922307284730776882365699575587e-25),
57  K(-2.7669765371483918815184949580784634161e-29),
58  K(6.231564149372584873279011515844227e-33),
59  K(-1.188050982913851622946881814029e-36),
60  K(1.88293159106694034780937099e-40),
61  K(-2.4019827304263718078055e-44),
62  K(2.329008315410200325e-48),
63  K(-1.5351885198203e-52),
64  K(5.185989964e-57),
65  };
66  static const R P2[] =
67  {
68  K( 131.0667020533290798466779416062094395070734202211890460026693857),
69  K(-245.6303545941878773983069709370348347580041325639555236454969282),
70  K( 204.5101554148308448423458719550952945685069457114308003995567211),
71  K(-150.5327320302921153754033870344894598759293143264072490756636477),
72  K( 98.7912567249134681293252237328232822188103014960829409778733265),
73  K(-57.7019241687318590480852440271548151666166507997357208465833492),
74  K( 30.1081598594932287475081756049550869990287890532877175670317803),
75  K(-14.0088712491952531569334147267018927351724433165829632848926311),
76  K( 5.8111909743388254524987383393719023598144356156326152933831237),
77  K(-2.1414136626793476610653760169160704073350780611789294609123711),
78  K( 0.698259559703142895902111022926235616592885506170181809796723),
79  K(-0.2001189347807367129846000381714457873845590394096920427488356),
80  K( 0.049988621846192684047867347253361546337456980171441178625268),
81  K(-0.0107553807128048320349112565182564637746370430259714241685807),
82  K( 0.0019628478791093008488874963820323167136472914702684286586238),
83  K(-0.0002975064821201439959012839810796951490827490578144599267114),
84  K( 0.0000363948822068787975159479880539390140326476204059270500102),
85  K(-3.4500354506312803346122587812035952285744626406680126004e-6),
86  K( 2.389194163273735466736165111640837640682648262451843124e-7),
87  K(-1.10522228579658847710719851107420853059835206797979003e-8),
88  K( 2.998585735858447897961231663140456464729911623332484e-10),
89  K(-3.9833617558882606404645795329229040634928477778665e-12),
90  K( 1.92588438006565847602499920031655017544553574078e-14),
91  K(-1.53988141966712757209882685942469734803820881e-17)
92  };
93  static const R Q2[] =
94  {
95  K(328.4489907350967829456654595549647170421869780143590268003242948),
96  K(-615.575319575198219705670766725559477112082560070865403723416427),
97  K(512.563661235514015228169012911053008163272899480360140632585558),
98  K(-377.3415411557897134242242685951784724031156711312221525972796826),
99  K(247.6887960380354072297631204916926385047383091206925653242453925),
100  K(-144.7079367047916629699737294050207521413589574809430211064537016),
101  K(75.5300501439366128901130531145623549019791219037305096822646727),
102  K(-35.1562871183824787711155827433330019401972267325168728838283815),
103  K(14.5900995053625141158588399870084373879991873744753473985888771),
104  K(-5.3793167684795558315535956122846115342243771791771104555817078),
105  K(1.7551860916884001665224751521627837644140913167505738803593836),
106  K(-0.5034275191915128601243198185547065251560284487106213345738464),
107  K(0.1258761177781805904401665597080296597844219207555140252667602),
108  K(-0.0271165711067811527517031577204913417520417117202287079370524),
109  K(0.0049566968097755025323253093106955508273120444565853663949773),
110  K(-0.0007529042621964042565348473109633952383792675486716081916002),
111  K(0.0000923845012025941529926888028246088283227759969619552077927),
112  K(-8.7971061636613823628316954758674029940675792754742342069e-6),
113  K(6.136252042100256280345626781919643641626278378156829218e-7),
114  K(-2.87514497545628209951433938237642236070094379906239019e-8),
115  K(7.99982739755782677965258184972152681716223485333226e-10),
116  K(-1.12250050360331111260828032356887810736651792918878e-11),
117  K(6.221827386743849038481605158298006999161167883e-14),
118  K(-8.0950402455773560717067392049638116407074069e-17)
119  };
120  #elif LDBL_MANT_DIG == 64
121  /* long double 96 bit wide */
122  static const R P1[] =
123  {
124  K(1.00696388290874250231638626673686646317801154370159972703168538),
125  K(0.243352848727738955738908687369450214577920342918851509272408866),
126  K(0.006964401160721188186398281247079919082283450941469460164590432),
127  K(0.000083047334117897959145500056901191736030823531931380263686302),
128  K(5.18256420384764810882467760619532575731801821889985626099e-7),
129  K(1.90790611016475818883461118145629029943434891680660527e-9),
130  K(4.44170587990105074420754325358582895345307949815573e-12),
131  K(6.805150196466153819995090798791966304827558189423e-15),
132  K(6.985104315031938858779570788468047860794936128e-18),
133  K(4.785507068734939741097928056648844894386614e-21),
134  K(2.117077490896605677726199140622837572025e-24),
135  K(5.52919580174986488729896702518475621e-28),
136  K(6.5666588969169003434516942087381e-32),
137  };
138  static const R Q1[] =
139  {
140  K(1.000011863675914860400478598182318948452642744176732473923183795358),
141  K(-0.006896324225185339751945118908659032102601115341265224641280055928),
142  K(0.00001186368725103095674191039208189536570056102297912907572890034),
143  K(-1.3496696876875206170114218872940978330152830864048922600366e-8),
144  K(1.1336174449932022007831556161183407392648142591512923821e-11),
145  K(-7.422841655569707018644701823047396523966712871897812e-15),
146  K(3.893669273036094904159100761627937282479044304922e-18),
147  K(-1.651720545895290413869725701665259282787265642e-21),
148  K(5.6323805635535562808481781647661895955232e-25),
149  K(-1.50728066570923164846664348266414336373e-28),
150  K(3.006044492319661074666639642233229e-32),
151  K(-4.010148023149017379419706572721e-36),
152  K(2.70282874465984817539266054e-40),
153  };
154  static const R P2[] =
155  {
156  K( 1.30090423521760256476093919023146864017751590623897710895862681),
157  K(-1.981041925270972574120174940817336830170017871902975653312750388),
158  K( 0.956892580228917795561363651877698243164566364537052353014543669),
159  K(-0.295476285312266394050596510402082979039773201845265239542019439),
160  K( 0.056978837924988815165935230495950981635872574537538384147033652),
161  K(-0.006299149197554616295736173514236214970859775932020376086036399),
162  K( 0.000353716966863384475462973243411450895641022763240331882363443),
163  K(-8.707624424632528381900923003415938761710942641810978203625e-6),
164  K( 7.283705999222063845686558855093093825421931939071318202e-8),
165  K(-9.7967727386492889920273780071218382357131320542055799e-11)
166  };
167  static const R Q2[] =
168  {
169  K( 3.257608431020108786259398271424889402309379351594793640349460063),
170  K(-4.96363276525502538609792324882976732173260916421950408693842731),
171  K( 2.400495835659089927333294199555080092801133193497330702140754591),
172  K(-0.742868968166381852162379299256973953894545292197384361382965225),
173  K( 0.143801810439830068463911726822151703498931831272162081681231077),
174  K(-0.016019224718850575023820322478614758671031103220377245057110662),
175  K( 0.000914623505897601721718970098041677534130323750396506936364887),
176  K(-0.000023411644633126949191317085153966622167096685843127825287574),
177  K( 2.17705048674331703171406080664526952334380771487046428339e-7),
178  K(-4.47580289731041130181939560179689655281441839562189718e-10)
179  };
180  #else
181  #error Unsupported size of long double
182  #endif
183 #elif defined(NFFT_SINGLE)
184  /* float */
185  static const R P1[] =
186  {
187  K(1.006634511033311726164163027592274220828216885723379609007274761),
188  K(0.240606487720090757394176928596156553834296465200311569457994763),
189  K(0.006634921274522227156198202198389031672287220144321235665461021),
190  K(0.000073749622820821337100502174723273851941734199062726870961819),
191  K(4.10243517822171814488230564074819973544765129449450710122e-7),
192  K(1.262110026222369902633819303536802438120823461060572684e-9),
193  K(2.218532296437410634454463125960648541194468552527652e-12),
194  K(2.141504045536019682125761418851096299425878119158e-15),
195  K(9.19584570350722374435337612379408707845677156e-19),
196  };
197  static const R Q1[] =
198  {
199  K(1.000022624782705275228334312456728477812835742762369533496905023937),
200  K(-0.009614857078745003693609489751018087358244444264456521971379273084),
201  K(0.000022624818652773047747424411495054891627754515915461183178099877),
202  K(-3.4080521639954323706277061786236961377055349443081338572762e-8),
203  K(3.5947512112800645225066705862453058797853924958888263259e-11),
204  K(-2.7149805873212658218594464017972758572144265290831215e-14),
205  K(1.4293388301569282795540255590126107486209476445158e-17),
206  K(-4.771887851505849942903948600229238419570937509e-21),
207  K(7.68298982666756594543081799488936861257839e-25),
208  };
209  static const R P2[] =
210  {
211  K( 0.400758393969643840397216812932361963736749407866811083462461),
212  K(-0.0312216150704950438088565774064329777860642477326179964345542),
213  K( 0.0001215451718646727844117193541329442989170354233955281424116)
214  };
215  static const R Q2[] =
216  {
217  K( 1.00043733569136882353241680221279480297575523819814430369272934),
218  K(-0.0822433017391967535749382764476705160129315137731445852657631),
219  K( 0.00043733569136882353241680221279480297575523819814430369272934)
220  };
221 #else
222  /* double */
223  static const R P1[] =
224  {
225  K(1.006897990143384859657820271920512961153421109156614230747188622),
226  K(0.242805341483041870658834102275462978674549112393424086979586278),
227  K(0.006898486035482686938510112687043665965094733332210445239567379),
228  K(0.000081165067173822070066416843139523709162208390998449005642346),
229  K(4.95896034564955471201271060753697747487292805350402943964e-7),
230  K(1.769262324717844587819564151110983803173733141412266849e-9),
231  K(3.936742942676484111899247866083681245613312522754135e-12),
232  K(5.65030097981781148787580946077568408874044779529e-15),
233  K(5.267856044117588097078633338366456262960465052e-18),
234  K(3.111192981528832405775039015470693622536939e-21),
235  K(1.071238669051606108411504195862449904664e-24),
236  K(1.66685455020362122704904175079692613e-28),
237  };
238  static const R Q1[] =
239  {
240  K(1.000013770640886533569435896302721489503868900260448440877422679934),
241  K(-0.007438195256024963574139196893944950727405523418354136393367554385),
242  K(0.000013770655915064256304772604385297068669909609091264440116789601),
243  K(-1.6794623118559896441239590667288215019925076196457659206142e-8),
244  K(1.50285363491992136130760477001818578470292828225498818e-11),
245  K(-1.0383232801211938342796582949062551517465351830706356e-14),
246  K(5.66233115275307483428203764087829782195312564006e-18),
247  K(-2.44062252162491829675666639093292109472275754e-21),
248  K(8.15441695513966815222186223740016719597617e-25),
249  K(-2.01117218503954384746303760121365911698e-28),
250  K(3.2919820158429806312377323449729691e-32),
251  K(-2.70343047912331415988664032397e-36),
252  };
253  static const R P2[] =
254  {
255  K( 0.4305671332839579065931339658100499864903788418438938270811),
256  K(-0.2897224581554843285637983312103876003389911968369470222427),
257  K( 0.0299419330186508349765969995362253891383950029259740306077),
258  K(-0.0010756807437990349677633120240742396555192749710627626584),
259  K( 0.0000116485185631252780743187413946316104574410146692335443),
260  K(-1.89995137955806752293614125586568854200245376235433e-08)
261  };
262  static const R Q2[] =
263  {
264  K(1.0762291019783101702628805159947862543863829764738274558421),
265  K(-0.7279167074883770739509279847502106137135422309409220238564),
266  K(0.0762629142282649564822465976300194596092279190843683614797),
267  K(-0.0028345107938479082322784040228834113914746923069059932628),
268  K(0.0000338122499547862193660816352332052228449426105409056376),
269  K(-8.28850093512263912295888947693700479250899073022595e-08)
270  };
271 #endif
272 
273 static const INT N1 = sizeof(P1)/sizeof(P1[0]);
274 static const INT M1 = sizeof(Q1)/sizeof(Q1[0]);
275 static const INT N2 = sizeof(P2)/sizeof(P2[0]);
276 static const INT M2 = sizeof(Q2)/sizeof(Q2[0]);
277 
278 static inline R evaluate_chebyshev(const INT n, const R *c, const R x)
279 {
280  R a = c[n-2], b = c[n-1], t;
281  int j;
282 
283  A(n >= 2);
284 
285  for (j = n - 2; j > 0; j--)
286  {
287  t = c[j-1] - b;
288  b = a + K(2.0) * x * b;
289  a = t;
290  }
291  return a + x * b;
292 }
293 
294 R X(bessel_i0)(R x)
295 {
296  if (x < 0)
297  {
298  /* even function */
299  x = -x;
300  }
301 
302  if (x == K(0.0))
303  return K(1.0);
304 
305  if (x <= K(15.0))
306  {
307  /* x in (0, 15] */
308  const R y = x * x;
309  return evaluate_chebyshev(N1, P1, y) / evaluate_chebyshev(M1, Q1, y);
310  }
311  else
312  {
313  /* x in (15, \infty) */
314  const R y = (K(30.0) - x) / x;
315  return (EXP(x) / SQRT(x)) * (evaluate_chebyshev(N2, P2, y) /
316  evaluate_chebyshev(M2, Q2, y));
317  }
318 }

Generated on Tue Apr 30 2013 by Doxygen 1.8.1