15b2ba9d3SPiotr Jasiukajtis /*
25b2ba9d3SPiotr Jasiukajtis * CDDL HEADER START
35b2ba9d3SPiotr Jasiukajtis *
45b2ba9d3SPiotr Jasiukajtis * The contents of this file are subject to the terms of the
55b2ba9d3SPiotr Jasiukajtis * Common Development and Distribution License (the "License").
65b2ba9d3SPiotr Jasiukajtis * You may not use this file except in compliance with the License.
75b2ba9d3SPiotr Jasiukajtis *
85b2ba9d3SPiotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95b2ba9d3SPiotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
105b2ba9d3SPiotr Jasiukajtis * See the License for the specific language governing permissions
115b2ba9d3SPiotr Jasiukajtis * and limitations under the License.
125b2ba9d3SPiotr Jasiukajtis *
135b2ba9d3SPiotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
145b2ba9d3SPiotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155b2ba9d3SPiotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
165b2ba9d3SPiotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
175b2ba9d3SPiotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
185b2ba9d3SPiotr Jasiukajtis *
195b2ba9d3SPiotr Jasiukajtis * CDDL HEADER END
205b2ba9d3SPiotr Jasiukajtis */
215b2ba9d3SPiotr Jasiukajtis /*
225b2ba9d3SPiotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
235b2ba9d3SPiotr Jasiukajtis */
245b2ba9d3SPiotr Jasiukajtis /*
255b2ba9d3SPiotr Jasiukajtis * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
265b2ba9d3SPiotr Jasiukajtis * Use is subject to license terms.
275b2ba9d3SPiotr Jasiukajtis */
285b2ba9d3SPiotr Jasiukajtis
29*a9d3dcd5SRichard Lowe #pragma weak __j0f = j0f
30*a9d3dcd5SRichard Lowe #pragma weak __j1f = j1f
31*a9d3dcd5SRichard Lowe #pragma weak __jnf = jnf
32*a9d3dcd5SRichard Lowe #pragma weak __y0f = y0f
33*a9d3dcd5SRichard Lowe #pragma weak __y1f = y1f
34*a9d3dcd5SRichard Lowe #pragma weak __ynf = ynf
355b2ba9d3SPiotr Jasiukajtis
365b2ba9d3SPiotr Jasiukajtis #include "libm.h"
375b2ba9d3SPiotr Jasiukajtis #include <float.h>
385b2ba9d3SPiotr Jasiukajtis
395b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
405b2ba9d3SPiotr Jasiukajtis extern int __swapRP(int);
415b2ba9d3SPiotr Jasiukajtis #endif
425b2ba9d3SPiotr Jasiukajtis
435b2ba9d3SPiotr Jasiukajtis static const float
445b2ba9d3SPiotr Jasiukajtis zerof = 0.0f,
455b2ba9d3SPiotr Jasiukajtis onef = 1.0f;
465b2ba9d3SPiotr Jasiukajtis
475b2ba9d3SPiotr Jasiukajtis static const double C[] = {
485b2ba9d3SPiotr Jasiukajtis 0.0,
495b2ba9d3SPiotr Jasiukajtis -0.125,
505b2ba9d3SPiotr Jasiukajtis 0.25,
515b2ba9d3SPiotr Jasiukajtis 0.375,
525b2ba9d3SPiotr Jasiukajtis 0.5,
535b2ba9d3SPiotr Jasiukajtis 1.0,
545b2ba9d3SPiotr Jasiukajtis 2.0,
555b2ba9d3SPiotr Jasiukajtis 8.0,
565b2ba9d3SPiotr Jasiukajtis 0.5641895835477562869480794515607725858441, /* 1/sqrt(pi) */
575b2ba9d3SPiotr Jasiukajtis 0.636619772367581343075535053490057448, /* 2/pi */
585b2ba9d3SPiotr Jasiukajtis 1.0e9,
595b2ba9d3SPiotr Jasiukajtis };
605b2ba9d3SPiotr Jasiukajtis
615b2ba9d3SPiotr Jasiukajtis #define zero C[0]
625b2ba9d3SPiotr Jasiukajtis #define neighth C[1]
635b2ba9d3SPiotr Jasiukajtis #define quarter C[2]
645b2ba9d3SPiotr Jasiukajtis #define three8 C[3]
655b2ba9d3SPiotr Jasiukajtis #define half C[4]
665b2ba9d3SPiotr Jasiukajtis #define one C[5]
675b2ba9d3SPiotr Jasiukajtis #define two C[6]
685b2ba9d3SPiotr Jasiukajtis #define eight C[7]
695b2ba9d3SPiotr Jasiukajtis #define isqrtpi C[8]
705b2ba9d3SPiotr Jasiukajtis #define tpi C[9]
715b2ba9d3SPiotr Jasiukajtis #define big C[10]
725b2ba9d3SPiotr Jasiukajtis
735b2ba9d3SPiotr Jasiukajtis static const double Cj0y0[] = {
745b2ba9d3SPiotr Jasiukajtis 0.4861344183386052721391238447e5, /* pr */
755b2ba9d3SPiotr Jasiukajtis 0.1377662549407112278133438945e6,
765b2ba9d3SPiotr Jasiukajtis 0.1222466364088289731869114004e6,
775b2ba9d3SPiotr Jasiukajtis 0.4107070084315176135583353374e5,
785b2ba9d3SPiotr Jasiukajtis 0.5026073801860637125889039915e4,
795b2ba9d3SPiotr Jasiukajtis 0.1783193659125479654541542419e3,
805b2ba9d3SPiotr Jasiukajtis 0.88010344055383421691677564e0,
815b2ba9d3SPiotr Jasiukajtis 0.4861344183386052721414037058e5, /* ps */
825b2ba9d3SPiotr Jasiukajtis 0.1378196632630384670477582699e6,
835b2ba9d3SPiotr Jasiukajtis 0.1223967185341006542748936787e6,
845b2ba9d3SPiotr Jasiukajtis 0.4120150243795353639995862617e5,
855b2ba9d3SPiotr Jasiukajtis 0.5068271181053546392490184353e4,
865b2ba9d3SPiotr Jasiukajtis 0.1829817905472769960535671664e3,
875b2ba9d3SPiotr Jasiukajtis 1.0,
885b2ba9d3SPiotr Jasiukajtis -0.1731210995701068539185611951e3, /* qr */
895b2ba9d3SPiotr Jasiukajtis -0.5522559165936166961235240613e3,
905b2ba9d3SPiotr Jasiukajtis -0.5604935606637346590614529613e3,
915b2ba9d3SPiotr Jasiukajtis -0.2200430300226009379477365011e3,
925b2ba9d3SPiotr Jasiukajtis -0.323869355375648849771296746e2,
935b2ba9d3SPiotr Jasiukajtis -0.14294979207907956223499258e1,
945b2ba9d3SPiotr Jasiukajtis -0.834690374102384988158918e-2,
955b2ba9d3SPiotr Jasiukajtis 0.1107975037248683865326709645e5, /* qs */
965b2ba9d3SPiotr Jasiukajtis 0.3544581680627082674651471873e5,
975b2ba9d3SPiotr Jasiukajtis 0.3619118937918394132179019059e5,
985b2ba9d3SPiotr Jasiukajtis 0.1439895563565398007471485822e5,
995b2ba9d3SPiotr Jasiukajtis 0.2190277023344363955930226234e4,
1005b2ba9d3SPiotr Jasiukajtis 0.106695157020407986137501682e3,
1015b2ba9d3SPiotr Jasiukajtis 1.0,
1025b2ba9d3SPiotr Jasiukajtis };
1035b2ba9d3SPiotr Jasiukajtis
1045b2ba9d3SPiotr Jasiukajtis #define pr Cj0y0
1055b2ba9d3SPiotr Jasiukajtis #define ps (Cj0y0+7)
1065b2ba9d3SPiotr Jasiukajtis #define qr (Cj0y0+14)
1075b2ba9d3SPiotr Jasiukajtis #define qs (Cj0y0+21)
1085b2ba9d3SPiotr Jasiukajtis
1095b2ba9d3SPiotr Jasiukajtis static const double Cj0[] = {
1105b2ba9d3SPiotr Jasiukajtis -2.500000000000003622131880894830476755537e-0001, /* r0 */
1115b2ba9d3SPiotr Jasiukajtis 1.095597547334830263234433855932375353303e-0002,
1125b2ba9d3SPiotr Jasiukajtis -1.819734750463320921799187258987098087697e-0004,
1135b2ba9d3SPiotr Jasiukajtis 9.977001946806131657544212501069893930846e-0007,
1145b2ba9d3SPiotr Jasiukajtis 1.0, /* s0 */
1155b2ba9d3SPiotr Jasiukajtis 1.867609810662950169966782360588199673741e-0002,
1165b2ba9d3SPiotr Jasiukajtis 1.590389206181565490878430827706972074208e-0004,
1175b2ba9d3SPiotr Jasiukajtis 6.520867386742583632375520147714499522721e-0007,
1185b2ba9d3SPiotr Jasiukajtis 9.999999999999999942156495584397047660949e-0001, /* r1 */
1195b2ba9d3SPiotr Jasiukajtis -2.389887722731319130476839836908143731281e-0001,
1205b2ba9d3SPiotr Jasiukajtis 1.293359476138939027791270393439493640570e-0002,
1215b2ba9d3SPiotr Jasiukajtis -2.770985642343140122168852400228563364082e-0004,
1225b2ba9d3SPiotr Jasiukajtis 2.905241575772067678086738389169625218912e-0006,
1235b2ba9d3SPiotr Jasiukajtis -1.636846356264052597969042009265043251279e-0008,
1245b2ba9d3SPiotr Jasiukajtis 5.072306160724884775085431059052611737827e-0011,
1255b2ba9d3SPiotr Jasiukajtis -8.187060730684066824228914775146536139112e-0014,
1265b2ba9d3SPiotr Jasiukajtis 5.422219326959949863954297860723723423842e-0017,
1275b2ba9d3SPiotr Jasiukajtis 1.0, /* s1 */
1285b2ba9d3SPiotr Jasiukajtis 1.101122772686807702762104741932076228349e-0002,
1295b2ba9d3SPiotr Jasiukajtis 6.140169310641649223411427764669143978228e-0005,
1305b2ba9d3SPiotr Jasiukajtis 2.292035877515152097976946119293215705250e-0007,
1315b2ba9d3SPiotr Jasiukajtis 6.356910426504644334558832036362219583789e-0010,
1325b2ba9d3SPiotr Jasiukajtis 1.366626326900219555045096999553948891401e-0012,
1335b2ba9d3SPiotr Jasiukajtis 2.280399586866739522891837985560481180088e-0015,
1345b2ba9d3SPiotr Jasiukajtis 2.801559820648939665270492520004836611187e-0018,
1355b2ba9d3SPiotr Jasiukajtis 2.073101088320349159764410261466350732968e-0021,
1365b2ba9d3SPiotr Jasiukajtis };
1375b2ba9d3SPiotr Jasiukajtis
1385b2ba9d3SPiotr Jasiukajtis #define r0 Cj0
1395b2ba9d3SPiotr Jasiukajtis #define s0 (Cj0+4)
1405b2ba9d3SPiotr Jasiukajtis #define r1 (Cj0+8)
1415b2ba9d3SPiotr Jasiukajtis #define s1 (Cj0+17)
1425b2ba9d3SPiotr Jasiukajtis
1435b2ba9d3SPiotr Jasiukajtis static const double Cy0[] = {
1445b2ba9d3SPiotr Jasiukajtis -7.380429510868722526754723020704317641941e-0002, /* u0 */
1455b2ba9d3SPiotr Jasiukajtis 1.772607102684869924301459663049874294814e-0001,
1465b2ba9d3SPiotr Jasiukajtis -1.524370666542713828604078090970799356306e-0002,
1475b2ba9d3SPiotr Jasiukajtis 4.650819100693891757143771557629924591915e-0004,
1485b2ba9d3SPiotr Jasiukajtis -7.125768872339528975036316108718239946022e-0006,
1495b2ba9d3SPiotr Jasiukajtis 6.411017001656104598327565004771515257146e-0008,
1505b2ba9d3SPiotr Jasiukajtis -3.694275157433032553021246812379258781665e-0010,
1515b2ba9d3SPiotr Jasiukajtis 1.434364544206266624252820889648445263842e-0012,
1525b2ba9d3SPiotr Jasiukajtis -3.852064731859936455895036286874139896861e-0015,
1535b2ba9d3SPiotr Jasiukajtis 7.182052899726138381739945881914874579696e-0018,
1545b2ba9d3SPiotr Jasiukajtis -9.060556574619677567323741194079797987200e-0021,
1555b2ba9d3SPiotr Jasiukajtis 7.124435467408860515265552217131230511455e-0024,
1565b2ba9d3SPiotr Jasiukajtis -2.709726774636397615328813121715432044771e-0027,
1575b2ba9d3SPiotr Jasiukajtis 1.0, /* v0 */
1585b2ba9d3SPiotr Jasiukajtis 4.678678931512549002587702477349214886475e-0003,
1595b2ba9d3SPiotr Jasiukajtis 9.486828955529948534822800829497565178985e-0006,
1605b2ba9d3SPiotr Jasiukajtis 1.001495929158861646659010844136682454906e-0008,
1615b2ba9d3SPiotr Jasiukajtis 4.725338116256021660204443235685358593611e-0012,
1625b2ba9d3SPiotr Jasiukajtis };
1635b2ba9d3SPiotr Jasiukajtis
1645b2ba9d3SPiotr Jasiukajtis #define u0 Cy0
1655b2ba9d3SPiotr Jasiukajtis #define v0 (Cy0+13)
1665b2ba9d3SPiotr Jasiukajtis
1675b2ba9d3SPiotr Jasiukajtis static const double Cj1y1[] = {
1685b2ba9d3SPiotr Jasiukajtis -0.4435757816794127857114720794e7, /* pr0 */
1695b2ba9d3SPiotr Jasiukajtis -0.9942246505077641195658377899e7,
1705b2ba9d3SPiotr Jasiukajtis -0.6603373248364939109255245434e7,
1715b2ba9d3SPiotr Jasiukajtis -0.1523529351181137383255105722e7,
1725b2ba9d3SPiotr Jasiukajtis -0.1098240554345934672737413139e6,
1735b2ba9d3SPiotr Jasiukajtis -0.1611616644324610116477412898e4,
1745b2ba9d3SPiotr Jasiukajtis -0.4435757816794127856828016962e7, /* ps0 */
1755b2ba9d3SPiotr Jasiukajtis -0.9934124389934585658967556309e7,
1765b2ba9d3SPiotr Jasiukajtis -0.6585339479723087072826915069e7,
1775b2ba9d3SPiotr Jasiukajtis -0.1511809506634160881644546358e7,
1785b2ba9d3SPiotr Jasiukajtis -0.1072638599110382011903063867e6,
1795b2ba9d3SPiotr Jasiukajtis -0.1455009440190496182453565068e4,
1805b2ba9d3SPiotr Jasiukajtis 0.3322091340985722351859704442e5, /* qr0 */
1815b2ba9d3SPiotr Jasiukajtis 0.8514516067533570196555001171e5,
1825b2ba9d3SPiotr Jasiukajtis 0.6617883658127083517939992166e5,
1835b2ba9d3SPiotr Jasiukajtis 0.1849426287322386679652009819e5,
1845b2ba9d3SPiotr Jasiukajtis 0.1706375429020768002061283546e4,
1855b2ba9d3SPiotr Jasiukajtis 0.3526513384663603218592175580e2,
1865b2ba9d3SPiotr Jasiukajtis 0.7087128194102874357377502472e6, /* qs0 */
1875b2ba9d3SPiotr Jasiukajtis 0.1819458042243997298924553839e7,
1885b2ba9d3SPiotr Jasiukajtis 0.1419460669603720892855755253e7,
1895b2ba9d3SPiotr Jasiukajtis 0.4002944358226697511708610813e6,
1905b2ba9d3SPiotr Jasiukajtis 0.3789022974577220264142952256e5,
1915b2ba9d3SPiotr Jasiukajtis 0.8638367769604990967475517183e3,
1925b2ba9d3SPiotr Jasiukajtis };
1935b2ba9d3SPiotr Jasiukajtis
1945b2ba9d3SPiotr Jasiukajtis #define pr0 Cj1y1
1955b2ba9d3SPiotr Jasiukajtis #define ps0 (Cj1y1+6)
1965b2ba9d3SPiotr Jasiukajtis #define qr0 (Cj1y1+12)
1975b2ba9d3SPiotr Jasiukajtis #define qs0 (Cj1y1+18)
1985b2ba9d3SPiotr Jasiukajtis
1995b2ba9d3SPiotr Jasiukajtis static const double Cj1[] = {
2005b2ba9d3SPiotr Jasiukajtis -6.250000000000002203053200981413218949548e-0002, /* a0 */
2015b2ba9d3SPiotr Jasiukajtis 1.600998455640072901321605101981501263762e-0003,
2025b2ba9d3SPiotr Jasiukajtis -1.963888815948313758552511884390162864930e-0005,
2035b2ba9d3SPiotr Jasiukajtis 8.263917341093549759781339713418201620998e-0008,
2045b2ba9d3SPiotr Jasiukajtis 1.0e0, /* b0 */
2055b2ba9d3SPiotr Jasiukajtis 1.605069137643004242395356851797873766927e-0002,
2065b2ba9d3SPiotr Jasiukajtis 1.149454623251299996428500249509098499383e-0004,
2075b2ba9d3SPiotr Jasiukajtis 3.849701673735260970379681807910852327825e-0007,
2085b2ba9d3SPiotr Jasiukajtis 4.999999999999999995517408894340485471724e-0001,
2095b2ba9d3SPiotr Jasiukajtis -6.003825028120475684835384519945468075423e-0002,
2105b2ba9d3SPiotr Jasiukajtis 2.301719899263321828388344461995355419832e-0003,
2115b2ba9d3SPiotr Jasiukajtis -4.208494869238892934859525221654040304068e-0005,
2125b2ba9d3SPiotr Jasiukajtis 4.377745135188837783031540029700282443388e-0007,
2135b2ba9d3SPiotr Jasiukajtis -2.854106755678624335145364226735677754179e-0009,
2145b2ba9d3SPiotr Jasiukajtis 1.234002865443952024332943901323798413689e-0011,
2155b2ba9d3SPiotr Jasiukajtis -3.645498437039791058951273508838177134310e-0014,
2165b2ba9d3SPiotr Jasiukajtis 7.404320596071797459925377103787837414422e-0017,
2175b2ba9d3SPiotr Jasiukajtis -1.009457448277522275262808398517024439084e-0019,
2185b2ba9d3SPiotr Jasiukajtis 8.520158355824819796968771418801019930585e-0023,
2195b2ba9d3SPiotr Jasiukajtis -3.458159926081163274483854614601091361424e-0026,
2205b2ba9d3SPiotr Jasiukajtis 1.0e0, /* b1 */
2215b2ba9d3SPiotr Jasiukajtis 4.923499437590484879081138588998986303306e-0003,
2225b2ba9d3SPiotr Jasiukajtis 1.054389489212184156499666953501976688452e-0005,
2235b2ba9d3SPiotr Jasiukajtis 1.180768373106166527048240364872043816050e-0008,
2245b2ba9d3SPiotr Jasiukajtis 5.942665743476099355323245707680648588540e-0012,
2255b2ba9d3SPiotr Jasiukajtis };
2265b2ba9d3SPiotr Jasiukajtis
2275b2ba9d3SPiotr Jasiukajtis #define a0 Cj1
2285b2ba9d3SPiotr Jasiukajtis #define b0 (Cj1+4)
2295b2ba9d3SPiotr Jasiukajtis #define a1 (Cj1+8)
2305b2ba9d3SPiotr Jasiukajtis #define b1 (Cj1+20)
2315b2ba9d3SPiotr Jasiukajtis
2325b2ba9d3SPiotr Jasiukajtis static const double Cy1[] = {
2335b2ba9d3SPiotr Jasiukajtis -1.960570906462389461018983259589655961560e-0001, /* c0 */
2345b2ba9d3SPiotr Jasiukajtis 4.931824118350661953459180060007970291139e-0002,
2355b2ba9d3SPiotr Jasiukajtis -1.626975871565393656845930125424683008677e-0003,
2365b2ba9d3SPiotr Jasiukajtis 1.359657517926394132692884168082224258360e-0005,
2375b2ba9d3SPiotr Jasiukajtis 1.0e0, /* d0 */
2385b2ba9d3SPiotr Jasiukajtis 2.565807214838390835108224713630901653793e-0002,
2395b2ba9d3SPiotr Jasiukajtis 3.374175208978404268650522752520906231508e-0004,
2405b2ba9d3SPiotr Jasiukajtis 2.840368571306070719539936935220728843177e-0006,
2415b2ba9d3SPiotr Jasiukajtis 1.396387402048998277638900944415752207592e-0008,
2425b2ba9d3SPiotr Jasiukajtis -1.960570906462389473336339614647555351626e-0001, /* c1 */
2435b2ba9d3SPiotr Jasiukajtis 5.336268030335074494231369159933012844735e-0002,
2445b2ba9d3SPiotr Jasiukajtis -2.684137504382748094149184541866332033280e-0003,
2455b2ba9d3SPiotr Jasiukajtis 5.737671618979185736981543498580051903060e-0005,
2465b2ba9d3SPiotr Jasiukajtis -6.642696350686335339171171785557663224892e-0007,
2475b2ba9d3SPiotr Jasiukajtis 4.692417922568160354012347591960362101664e-0009,
2485b2ba9d3SPiotr Jasiukajtis -2.161728635907789319335231338621412258355e-0011,
2495b2ba9d3SPiotr Jasiukajtis 6.727353419738316107197644431844194668702e-0014,
2505b2ba9d3SPiotr Jasiukajtis -1.427502986803861372125234355906790573422e-0016,
2515b2ba9d3SPiotr Jasiukajtis 2.020392498726806769468143219616642940371e-0019,
2525b2ba9d3SPiotr Jasiukajtis -1.761371948595104156753045457888272716340e-0022,
2535b2ba9d3SPiotr Jasiukajtis 7.352828391941157905175042420249225115816e-0026,
2545b2ba9d3SPiotr Jasiukajtis 1.0e0, /* d1 */
2555b2ba9d3SPiotr Jasiukajtis 5.029187436727947764916247076102283399442e-0003,
2565b2ba9d3SPiotr Jasiukajtis 1.102693095808242775074856548927801750627e-0005,
2575b2ba9d3SPiotr Jasiukajtis 1.268035774543174837829534603830227216291e-0008,
2585b2ba9d3SPiotr Jasiukajtis 6.579416271766610825192542295821308730206e-0012,
2595b2ba9d3SPiotr Jasiukajtis };
2605b2ba9d3SPiotr Jasiukajtis
2615b2ba9d3SPiotr Jasiukajtis #define c0 Cy1
2625b2ba9d3SPiotr Jasiukajtis #define d0 (Cy1+4)
2635b2ba9d3SPiotr Jasiukajtis #define c1 (Cy1+9)
2645b2ba9d3SPiotr Jasiukajtis #define d1 (Cy1+21)
2655b2ba9d3SPiotr Jasiukajtis
2665b2ba9d3SPiotr Jasiukajtis
2675b2ba9d3SPiotr Jasiukajtis /* core of j0f computation; assumes fx is finite */
2685b2ba9d3SPiotr Jasiukajtis static double
__k_j0f(float fx)2695b2ba9d3SPiotr Jasiukajtis __k_j0f(float fx)
2705b2ba9d3SPiotr Jasiukajtis {
2715b2ba9d3SPiotr Jasiukajtis double x, z, s, c, ss, cc, r, t, p0, q0;
2725b2ba9d3SPiotr Jasiukajtis int ix, i;
2735b2ba9d3SPiotr Jasiukajtis
2745b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx & ~0x80000000;
2755b2ba9d3SPiotr Jasiukajtis x = fabs((double)fx);
2765b2ba9d3SPiotr Jasiukajtis if (ix > 0x41000000) {
2775b2ba9d3SPiotr Jasiukajtis /* x > 8; see comments in j0.c */
2785b2ba9d3SPiotr Jasiukajtis s = sin(x);
2795b2ba9d3SPiotr Jasiukajtis c = cos(x);
2805b2ba9d3SPiotr Jasiukajtis if (signbit(s) != signbit(c)) {
2815b2ba9d3SPiotr Jasiukajtis ss = s - c;
2825b2ba9d3SPiotr Jasiukajtis cc = -cos(x + x) / ss;
2835b2ba9d3SPiotr Jasiukajtis } else {
2845b2ba9d3SPiotr Jasiukajtis cc = s + c;
2855b2ba9d3SPiotr Jasiukajtis ss = -cos(x + x) / cc;
2865b2ba9d3SPiotr Jasiukajtis }
2875b2ba9d3SPiotr Jasiukajtis if (ix > 0x501502f9) {
2885b2ba9d3SPiotr Jasiukajtis /* x > 1.0e10 */
2895b2ba9d3SPiotr Jasiukajtis p0 = one;
2905b2ba9d3SPiotr Jasiukajtis q0 = neighth / x;
2915b2ba9d3SPiotr Jasiukajtis } else {
2925b2ba9d3SPiotr Jasiukajtis t = eight / x;
2935b2ba9d3SPiotr Jasiukajtis z = t * t;
2945b2ba9d3SPiotr Jasiukajtis p0 = (pr[0] + z * (pr[1] + z * (pr[2] + z * (pr[3] +
2955b2ba9d3SPiotr Jasiukajtis z * (pr[4] + z * (pr[5] + z * pr[6])))))) /
2965b2ba9d3SPiotr Jasiukajtis (ps[0] + z * (ps[1] + z * (ps[2] + z * (ps[3] +
2975b2ba9d3SPiotr Jasiukajtis z * (ps[4] + z * (ps[5] + z))))));
2985b2ba9d3SPiotr Jasiukajtis q0 = ((qr[0] + z * (qr[1] + z * (qr[2] + z * (qr[3] +
2995b2ba9d3SPiotr Jasiukajtis z * (qr[4] + z * (qr[5] + z * qr[6])))))) /
3005b2ba9d3SPiotr Jasiukajtis (qs[0] + z * (qs[1] + z * (qs[2] + z * (qs[3] +
3015b2ba9d3SPiotr Jasiukajtis z * (qs[4] + z * (qs[5] + z))))))) * t;
3025b2ba9d3SPiotr Jasiukajtis }
3035b2ba9d3SPiotr Jasiukajtis return (isqrtpi * (p0 * cc - q0 * ss) / sqrt(x));
3045b2ba9d3SPiotr Jasiukajtis }
3055b2ba9d3SPiotr Jasiukajtis if (ix <= 0x3727c5ac) {
3065b2ba9d3SPiotr Jasiukajtis /* x <= 1.0e-5 */
3075b2ba9d3SPiotr Jasiukajtis if (ix <= 0x219392ef) /* x <= 1.0e-18 */
3085b2ba9d3SPiotr Jasiukajtis return (one - x);
3095b2ba9d3SPiotr Jasiukajtis return (one - x * x * quarter);
3105b2ba9d3SPiotr Jasiukajtis }
3115b2ba9d3SPiotr Jasiukajtis z = x * x;
3125b2ba9d3SPiotr Jasiukajtis if (ix <= 0x3fa3d70a) {
3135b2ba9d3SPiotr Jasiukajtis /* x <= 1.28 */
3145b2ba9d3SPiotr Jasiukajtis r = r0[0] + z * (r0[1] + z * (r0[2] + z * r0[3]));
3155b2ba9d3SPiotr Jasiukajtis s = s0[0] + z * (s0[1] + z * (s0[2] + z * s0[3]));
3165b2ba9d3SPiotr Jasiukajtis return (one + z * (r / s));
3175b2ba9d3SPiotr Jasiukajtis }
3185b2ba9d3SPiotr Jasiukajtis r = r1[8];
3195b2ba9d3SPiotr Jasiukajtis s = s1[8];
3205b2ba9d3SPiotr Jasiukajtis for (i = 7; i >= 0; i--) {
3215b2ba9d3SPiotr Jasiukajtis r = r * z + r1[i];
3225b2ba9d3SPiotr Jasiukajtis s = s * z + s1[i];
3235b2ba9d3SPiotr Jasiukajtis }
3245b2ba9d3SPiotr Jasiukajtis return (r / s);
3255b2ba9d3SPiotr Jasiukajtis }
3265b2ba9d3SPiotr Jasiukajtis
3275b2ba9d3SPiotr Jasiukajtis float
j0f(float fx)3285b2ba9d3SPiotr Jasiukajtis j0f(float fx)
3295b2ba9d3SPiotr Jasiukajtis {
3305b2ba9d3SPiotr Jasiukajtis float f;
3315b2ba9d3SPiotr Jasiukajtis int ix;
3325b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
3335b2ba9d3SPiotr Jasiukajtis int rp;
3345b2ba9d3SPiotr Jasiukajtis #endif
3355b2ba9d3SPiotr Jasiukajtis
3365b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx & ~0x80000000;
3375b2ba9d3SPiotr Jasiukajtis if (ix >= 0x7f800000) { /* nan or inf */
3385b2ba9d3SPiotr Jasiukajtis if (ix > 0x7f800000)
3395b2ba9d3SPiotr Jasiukajtis return (fx * fx);
3405b2ba9d3SPiotr Jasiukajtis return (zerof);
3415b2ba9d3SPiotr Jasiukajtis }
3425b2ba9d3SPiotr Jasiukajtis
3435b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
3445b2ba9d3SPiotr Jasiukajtis rp = __swapRP(fp_extended);
3455b2ba9d3SPiotr Jasiukajtis #endif
3465b2ba9d3SPiotr Jasiukajtis f = (float)__k_j0f(fx);
3475b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
3485b2ba9d3SPiotr Jasiukajtis if (rp != fp_extended)
3495b2ba9d3SPiotr Jasiukajtis (void) __swapRP(rp);
3505b2ba9d3SPiotr Jasiukajtis #endif
3515b2ba9d3SPiotr Jasiukajtis return (f);
3525b2ba9d3SPiotr Jasiukajtis }
3535b2ba9d3SPiotr Jasiukajtis
3545b2ba9d3SPiotr Jasiukajtis /* core of y0f computation; assumes fx is finite and positive */
3555b2ba9d3SPiotr Jasiukajtis static double
__k_y0f(float fx)3565b2ba9d3SPiotr Jasiukajtis __k_y0f(float fx)
3575b2ba9d3SPiotr Jasiukajtis {
3585b2ba9d3SPiotr Jasiukajtis double x, z, s, c, ss, cc, t, p0, q0, u, v;
3595b2ba9d3SPiotr Jasiukajtis int ix, i;
3605b2ba9d3SPiotr Jasiukajtis
3615b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx;
3625b2ba9d3SPiotr Jasiukajtis x = (double)fx;
3635b2ba9d3SPiotr Jasiukajtis if (ix > 0x41000000) {
3645b2ba9d3SPiotr Jasiukajtis /* x > 8; see comments in j0.c */
3655b2ba9d3SPiotr Jasiukajtis s = sin(x);
3665b2ba9d3SPiotr Jasiukajtis c = cos(x);
3675b2ba9d3SPiotr Jasiukajtis if (signbit(s) != signbit(c)) {
3685b2ba9d3SPiotr Jasiukajtis ss = s - c;
3695b2ba9d3SPiotr Jasiukajtis cc = -cos(x + x) / ss;
3705b2ba9d3SPiotr Jasiukajtis } else {
3715b2ba9d3SPiotr Jasiukajtis cc = s + c;
3725b2ba9d3SPiotr Jasiukajtis ss = -cos(x + x) / cc;
3735b2ba9d3SPiotr Jasiukajtis }
3745b2ba9d3SPiotr Jasiukajtis if (ix > 0x501502f9) {
3755b2ba9d3SPiotr Jasiukajtis /* x > 1.0e10 */
3765b2ba9d3SPiotr Jasiukajtis p0 = one;
3775b2ba9d3SPiotr Jasiukajtis q0 = neighth / x;
3785b2ba9d3SPiotr Jasiukajtis } else {
3795b2ba9d3SPiotr Jasiukajtis t = eight / x;
3805b2ba9d3SPiotr Jasiukajtis z = t * t;
3815b2ba9d3SPiotr Jasiukajtis p0 = (pr[0] + z * (pr[1] + z * (pr[2] + z * (pr[3] +
3825b2ba9d3SPiotr Jasiukajtis z * (pr[4] + z * (pr[5] + z * pr[6])))))) /
3835b2ba9d3SPiotr Jasiukajtis (ps[0] + z * (ps[1] + z * (ps[2] + z * (ps[3] +
3845b2ba9d3SPiotr Jasiukajtis z * (ps[4] + z * (ps[5] + z))))));
3855b2ba9d3SPiotr Jasiukajtis q0 = ((qr[0] + z * (qr[1] + z * (qr[2] + z * (qr[3] +
3865b2ba9d3SPiotr Jasiukajtis z * (qr[4] + z * (qr[5] + z * qr[6])))))) /
3875b2ba9d3SPiotr Jasiukajtis (qs[0] + z * (qs[1] + z * (qs[2] + z * (qs[3] +
3885b2ba9d3SPiotr Jasiukajtis z * (qs[4] + z * (qs[5] + z))))))) * t;
3895b2ba9d3SPiotr Jasiukajtis }
3905b2ba9d3SPiotr Jasiukajtis return (isqrtpi * (p0 * ss + q0 * cc) / sqrt(x));
3915b2ba9d3SPiotr Jasiukajtis }
3925b2ba9d3SPiotr Jasiukajtis if (ix <= 0x219392ef) /* x <= 1.0e-18 */
3935b2ba9d3SPiotr Jasiukajtis return (u0[0] + tpi * log(x));
3945b2ba9d3SPiotr Jasiukajtis z = x * x;
3955b2ba9d3SPiotr Jasiukajtis u = u0[12];
3965b2ba9d3SPiotr Jasiukajtis for (i = 11; i >= 0; i--)
3975b2ba9d3SPiotr Jasiukajtis u = u * z + u0[i];
3985b2ba9d3SPiotr Jasiukajtis v = v0[0] + z * (v0[1] + z * (v0[2] + z * (v0[3] + z * v0[4])));
3995b2ba9d3SPiotr Jasiukajtis return (u / v + tpi * (__k_j0f(fx) * log(x)));
4005b2ba9d3SPiotr Jasiukajtis }
4015b2ba9d3SPiotr Jasiukajtis
4025b2ba9d3SPiotr Jasiukajtis float
y0f(float fx)4035b2ba9d3SPiotr Jasiukajtis y0f(float fx)
4045b2ba9d3SPiotr Jasiukajtis {
4055b2ba9d3SPiotr Jasiukajtis float f;
4065b2ba9d3SPiotr Jasiukajtis int ix;
4075b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
4085b2ba9d3SPiotr Jasiukajtis int rp;
4095b2ba9d3SPiotr Jasiukajtis #endif
4105b2ba9d3SPiotr Jasiukajtis
4115b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx;
4125b2ba9d3SPiotr Jasiukajtis if ((ix & ~0x80000000) > 0x7f800000) /* nan */
4135b2ba9d3SPiotr Jasiukajtis return (fx * fx);
4145b2ba9d3SPiotr Jasiukajtis if (ix <= 0) { /* zero or negative */
4155b2ba9d3SPiotr Jasiukajtis if ((ix << 1) == 0)
4165b2ba9d3SPiotr Jasiukajtis return (-onef / zerof);
4175b2ba9d3SPiotr Jasiukajtis return (zerof / zerof);
4185b2ba9d3SPiotr Jasiukajtis }
4195b2ba9d3SPiotr Jasiukajtis if (ix == 0x7f800000) /* +inf */
4205b2ba9d3SPiotr Jasiukajtis return (zerof);
4215b2ba9d3SPiotr Jasiukajtis
4225b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
4235b2ba9d3SPiotr Jasiukajtis rp = __swapRP(fp_extended);
4245b2ba9d3SPiotr Jasiukajtis #endif
4255b2ba9d3SPiotr Jasiukajtis f = (float)__k_y0f(fx);
4265b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
4275b2ba9d3SPiotr Jasiukajtis if (rp != fp_extended)
4285b2ba9d3SPiotr Jasiukajtis (void) __swapRP(rp);
4295b2ba9d3SPiotr Jasiukajtis #endif
4305b2ba9d3SPiotr Jasiukajtis return (f);
4315b2ba9d3SPiotr Jasiukajtis }
4325b2ba9d3SPiotr Jasiukajtis
4335b2ba9d3SPiotr Jasiukajtis /* core of j1f computation; assumes fx is finite */
4345b2ba9d3SPiotr Jasiukajtis static double
__k_j1f(float fx)4355b2ba9d3SPiotr Jasiukajtis __k_j1f(float fx)
4365b2ba9d3SPiotr Jasiukajtis {
4375b2ba9d3SPiotr Jasiukajtis double x, z, s, c, ss, cc, r, t, p1, q1;
4385b2ba9d3SPiotr Jasiukajtis int i, ix, sgn;
4395b2ba9d3SPiotr Jasiukajtis
4405b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx;
4415b2ba9d3SPiotr Jasiukajtis sgn = (unsigned)ix >> 31;
4425b2ba9d3SPiotr Jasiukajtis ix &= ~0x80000000;
4435b2ba9d3SPiotr Jasiukajtis x = fabs((double)fx);
4445b2ba9d3SPiotr Jasiukajtis if (ix > 0x41000000) {
4455b2ba9d3SPiotr Jasiukajtis /* x > 8; see comments in j1.c */
4465b2ba9d3SPiotr Jasiukajtis s = sin(x);
4475b2ba9d3SPiotr Jasiukajtis c = cos(x);
4485b2ba9d3SPiotr Jasiukajtis if (signbit(s) != signbit(c)) {
4495b2ba9d3SPiotr Jasiukajtis cc = s - c;
4505b2ba9d3SPiotr Jasiukajtis ss = cos(x + x) / cc;
4515b2ba9d3SPiotr Jasiukajtis } else {
4525b2ba9d3SPiotr Jasiukajtis ss = -s - c;
4535b2ba9d3SPiotr Jasiukajtis cc = cos(x + x) / ss;
4545b2ba9d3SPiotr Jasiukajtis }
4555b2ba9d3SPiotr Jasiukajtis if (ix > 0x501502f9) {
4565b2ba9d3SPiotr Jasiukajtis /* x > 1.0e10 */
4575b2ba9d3SPiotr Jasiukajtis p1 = one;
4585b2ba9d3SPiotr Jasiukajtis q1 = three8 / x;
4595b2ba9d3SPiotr Jasiukajtis } else {
4605b2ba9d3SPiotr Jasiukajtis t = eight / x;
4615b2ba9d3SPiotr Jasiukajtis z = t * t;
4625b2ba9d3SPiotr Jasiukajtis p1 = (pr0[0] + z * (pr0[1] + z * (pr0[2] + z *
4635b2ba9d3SPiotr Jasiukajtis (pr0[3] + z * (pr0[4] + z * pr0[5]))))) /
4645b2ba9d3SPiotr Jasiukajtis (ps0[0] + z * (ps0[1] + z * (ps0[2] + z *
4655b2ba9d3SPiotr Jasiukajtis (ps0[3] + z * (ps0[4] + z * (ps0[5] + z))))));
4665b2ba9d3SPiotr Jasiukajtis q1 = ((qr0[0] + z * (qr0[1] + z * (qr0[2] + z *
4675b2ba9d3SPiotr Jasiukajtis (qr0[3] + z * (qr0[4] + z * qr0[5]))))) /
4685b2ba9d3SPiotr Jasiukajtis (qs0[0] + z * (qs0[1] + z * (qs0[2] + z *
4695b2ba9d3SPiotr Jasiukajtis (qs0[3] + z * (qs0[4] + z * (qs0[5] + z))))))) * t;
4705b2ba9d3SPiotr Jasiukajtis }
4715b2ba9d3SPiotr Jasiukajtis t = isqrtpi * (p1 * cc - q1 * ss) / sqrt(x);
4725b2ba9d3SPiotr Jasiukajtis return ((sgn)? -t : t);
4735b2ba9d3SPiotr Jasiukajtis }
4745b2ba9d3SPiotr Jasiukajtis if (ix <= 0x3727c5ac) {
4755b2ba9d3SPiotr Jasiukajtis /* x <= 1.0e-5 */
4765b2ba9d3SPiotr Jasiukajtis if (ix <= 0x219392ef) /* x <= 1.0e-18 */
4775b2ba9d3SPiotr Jasiukajtis t = half * x;
4785b2ba9d3SPiotr Jasiukajtis else
4795b2ba9d3SPiotr Jasiukajtis t = x * (half + neighth * x * x);
4805b2ba9d3SPiotr Jasiukajtis return ((sgn)? -t : t);
4815b2ba9d3SPiotr Jasiukajtis }
4825b2ba9d3SPiotr Jasiukajtis z = x * x;
4835b2ba9d3SPiotr Jasiukajtis if (ix < 0x3fa3d70a) {
4845b2ba9d3SPiotr Jasiukajtis /* x < 1.28 */
4855b2ba9d3SPiotr Jasiukajtis r = a0[0] + z * (a0[1] + z * (a0[2] + z * a0[3]));
4865b2ba9d3SPiotr Jasiukajtis s = b0[0] + z * (b0[1] + z * (b0[2] + z * b0[3]));
4875b2ba9d3SPiotr Jasiukajtis t = x * half + x * (z * (r / s));
4885b2ba9d3SPiotr Jasiukajtis } else {
4895b2ba9d3SPiotr Jasiukajtis r = a1[11];
4905b2ba9d3SPiotr Jasiukajtis for (i = 10; i >= 0; i--)
4915b2ba9d3SPiotr Jasiukajtis r = r * z + a1[i];
4925b2ba9d3SPiotr Jasiukajtis s = b1[0] + z * (b1[1] + z * (b1[2] + z * (b1[3] + z * b1[4])));
4935b2ba9d3SPiotr Jasiukajtis t = x * (r / s);
4945b2ba9d3SPiotr Jasiukajtis }
4955b2ba9d3SPiotr Jasiukajtis return ((sgn)? -t : t);
4965b2ba9d3SPiotr Jasiukajtis }
4975b2ba9d3SPiotr Jasiukajtis
4985b2ba9d3SPiotr Jasiukajtis float
j1f(float fx)4995b2ba9d3SPiotr Jasiukajtis j1f(float fx)
5005b2ba9d3SPiotr Jasiukajtis {
5015b2ba9d3SPiotr Jasiukajtis float f;
5025b2ba9d3SPiotr Jasiukajtis int ix;
5035b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
5045b2ba9d3SPiotr Jasiukajtis int rp;
5055b2ba9d3SPiotr Jasiukajtis #endif
5065b2ba9d3SPiotr Jasiukajtis
5075b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx & ~0x80000000;
5085b2ba9d3SPiotr Jasiukajtis if (ix >= 0x7f800000) /* nan or inf */
5095b2ba9d3SPiotr Jasiukajtis return (onef / fx);
5105b2ba9d3SPiotr Jasiukajtis
5115b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
5125b2ba9d3SPiotr Jasiukajtis rp = __swapRP(fp_extended);
5135b2ba9d3SPiotr Jasiukajtis #endif
5145b2ba9d3SPiotr Jasiukajtis f = (float)__k_j1f(fx);
5155b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
5165b2ba9d3SPiotr Jasiukajtis if (rp != fp_extended)
5175b2ba9d3SPiotr Jasiukajtis (void) __swapRP(rp);
5185b2ba9d3SPiotr Jasiukajtis #endif
5195b2ba9d3SPiotr Jasiukajtis return (f);
5205b2ba9d3SPiotr Jasiukajtis }
5215b2ba9d3SPiotr Jasiukajtis
5225b2ba9d3SPiotr Jasiukajtis /* core of y1f computation; assumes fx is finite and positive */
5235b2ba9d3SPiotr Jasiukajtis static double
__k_y1f(float fx)5245b2ba9d3SPiotr Jasiukajtis __k_y1f(float fx)
5255b2ba9d3SPiotr Jasiukajtis {
5265b2ba9d3SPiotr Jasiukajtis double x, z, s, c, ss, cc, u, v, p1, q1, t;
5275b2ba9d3SPiotr Jasiukajtis int i, ix;
5285b2ba9d3SPiotr Jasiukajtis
5295b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx;
5305b2ba9d3SPiotr Jasiukajtis x = (double)fx;
5315b2ba9d3SPiotr Jasiukajtis if (ix > 0x41000000) {
5325b2ba9d3SPiotr Jasiukajtis /* x > 8; see comments in j1.c */
5335b2ba9d3SPiotr Jasiukajtis s = sin(x);
5345b2ba9d3SPiotr Jasiukajtis c = cos(x);
5355b2ba9d3SPiotr Jasiukajtis if (signbit(s) != signbit(c)) {
5365b2ba9d3SPiotr Jasiukajtis cc = s - c;
5375b2ba9d3SPiotr Jasiukajtis ss = cos(x + x) / cc;
5385b2ba9d3SPiotr Jasiukajtis } else {
5395b2ba9d3SPiotr Jasiukajtis ss = -s - c;
5405b2ba9d3SPiotr Jasiukajtis cc = cos(x + x) / ss;
5415b2ba9d3SPiotr Jasiukajtis }
5425b2ba9d3SPiotr Jasiukajtis if (ix > 0x501502f9) {
5435b2ba9d3SPiotr Jasiukajtis /* x > 1.0e10 */
5445b2ba9d3SPiotr Jasiukajtis p1 = one;
5455b2ba9d3SPiotr Jasiukajtis q1 = three8 / x;
5465b2ba9d3SPiotr Jasiukajtis } else {
5475b2ba9d3SPiotr Jasiukajtis t = eight / x;
5485b2ba9d3SPiotr Jasiukajtis z = t * t;
5495b2ba9d3SPiotr Jasiukajtis p1 = (pr0[0] + z * (pr0[1] + z * (pr0[2] + z *
5505b2ba9d3SPiotr Jasiukajtis (pr0[3] + z * (pr0[4] + z * pr0[5]))))) /
5515b2ba9d3SPiotr Jasiukajtis (ps0[0] + z * (ps0[1] + z * (ps0[2] + z *
5525b2ba9d3SPiotr Jasiukajtis (ps0[3] + z * (ps0[4] + z * (ps0[5] + z))))));
5535b2ba9d3SPiotr Jasiukajtis q1 = ((qr0[0] + z * (qr0[1] + z * (qr0[2] + z *
5545b2ba9d3SPiotr Jasiukajtis (qr0[3] + z * (qr0[4] + z * qr0[5]))))) /
5555b2ba9d3SPiotr Jasiukajtis (qs0[0] + z * (qs0[1] + z * (qs0[2] + z *
5565b2ba9d3SPiotr Jasiukajtis (qs0[3] + z * (qs0[4] + z * (qs0[5] + z))))))) * t;
5575b2ba9d3SPiotr Jasiukajtis }
5585b2ba9d3SPiotr Jasiukajtis return (isqrtpi * (p1 * ss + q1 * cc) / sqrt(x));
5595b2ba9d3SPiotr Jasiukajtis }
5605b2ba9d3SPiotr Jasiukajtis if (ix <= 0x219392ef) /* x <= 1.0e-18 */
5615b2ba9d3SPiotr Jasiukajtis return (-tpi / x);
5625b2ba9d3SPiotr Jasiukajtis z = x * x;
5635b2ba9d3SPiotr Jasiukajtis if (ix < 0x3fa3d70a) {
5645b2ba9d3SPiotr Jasiukajtis /* x < 1.28 */
5655b2ba9d3SPiotr Jasiukajtis u = c0[0] + z * (c0[1] + z * (c0[2] + z * c0[3]));
5665b2ba9d3SPiotr Jasiukajtis v = d0[0] + z * (d0[1] + z * (d0[2] + z * (d0[3] + z * d0[4])));
5675b2ba9d3SPiotr Jasiukajtis } else {
5685b2ba9d3SPiotr Jasiukajtis u = c1[11];
5695b2ba9d3SPiotr Jasiukajtis for (i = 10; i >= 0; i--)
5705b2ba9d3SPiotr Jasiukajtis u = u * z + c1[i];
5715b2ba9d3SPiotr Jasiukajtis v = d1[0] + z * (d1[1] + z * (d1[2] + z * (d1[3] + z * d1[4])));
5725b2ba9d3SPiotr Jasiukajtis }
5735b2ba9d3SPiotr Jasiukajtis return (x * (u / v) + tpi * (__k_j1f(fx) * log(x) - one / x));
5745b2ba9d3SPiotr Jasiukajtis }
5755b2ba9d3SPiotr Jasiukajtis
5765b2ba9d3SPiotr Jasiukajtis float
y1f(float fx)5775b2ba9d3SPiotr Jasiukajtis y1f(float fx)
5785b2ba9d3SPiotr Jasiukajtis {
5795b2ba9d3SPiotr Jasiukajtis float f;
5805b2ba9d3SPiotr Jasiukajtis int ix;
5815b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
5825b2ba9d3SPiotr Jasiukajtis int rp;
5835b2ba9d3SPiotr Jasiukajtis #endif
5845b2ba9d3SPiotr Jasiukajtis
5855b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx;
5865b2ba9d3SPiotr Jasiukajtis if ((ix & ~0x80000000) > 0x7f800000) /* nan */
5875b2ba9d3SPiotr Jasiukajtis return (fx * fx);
5885b2ba9d3SPiotr Jasiukajtis if (ix <= 0) { /* zero or negative */
5895b2ba9d3SPiotr Jasiukajtis if ((ix << 1) == 0)
5905b2ba9d3SPiotr Jasiukajtis return (-onef / zerof);
5915b2ba9d3SPiotr Jasiukajtis return (zerof / zerof);
5925b2ba9d3SPiotr Jasiukajtis }
5935b2ba9d3SPiotr Jasiukajtis if (ix == 0x7f800000) /* +inf */
5945b2ba9d3SPiotr Jasiukajtis return (zerof);
5955b2ba9d3SPiotr Jasiukajtis
5965b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
5975b2ba9d3SPiotr Jasiukajtis rp = __swapRP(fp_extended);
5985b2ba9d3SPiotr Jasiukajtis #endif
5995b2ba9d3SPiotr Jasiukajtis f = (float)__k_y1f(fx);
6005b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
6015b2ba9d3SPiotr Jasiukajtis if (rp != fp_extended)
6025b2ba9d3SPiotr Jasiukajtis (void) __swapRP(rp);
6035b2ba9d3SPiotr Jasiukajtis #endif
6045b2ba9d3SPiotr Jasiukajtis return (f);
6055b2ba9d3SPiotr Jasiukajtis }
6065b2ba9d3SPiotr Jasiukajtis
6075b2ba9d3SPiotr Jasiukajtis float
jnf(int n,float fx)6085b2ba9d3SPiotr Jasiukajtis jnf(int n, float fx)
6095b2ba9d3SPiotr Jasiukajtis {
6105b2ba9d3SPiotr Jasiukajtis double a, b, temp, x, z, w, t, q0, q1, h;
6115b2ba9d3SPiotr Jasiukajtis float f;
6125b2ba9d3SPiotr Jasiukajtis int i, ix, sgn, m, k;
6135b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
6145b2ba9d3SPiotr Jasiukajtis int rp;
6155b2ba9d3SPiotr Jasiukajtis #endif
6165b2ba9d3SPiotr Jasiukajtis
6175b2ba9d3SPiotr Jasiukajtis if (n < 0) {
6185b2ba9d3SPiotr Jasiukajtis n = -n;
6195b2ba9d3SPiotr Jasiukajtis fx = -fx;
6205b2ba9d3SPiotr Jasiukajtis }
6215b2ba9d3SPiotr Jasiukajtis if (n == 0)
6225b2ba9d3SPiotr Jasiukajtis return (j0f(fx));
6235b2ba9d3SPiotr Jasiukajtis if (n == 1)
6245b2ba9d3SPiotr Jasiukajtis return (j1f(fx));
6255b2ba9d3SPiotr Jasiukajtis
6265b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx;
6275b2ba9d3SPiotr Jasiukajtis sgn = (n & 1)? ((unsigned)ix >> 31) : 0;
6285b2ba9d3SPiotr Jasiukajtis ix &= ~0x80000000;
6295b2ba9d3SPiotr Jasiukajtis if (ix >= 0x7f800000) { /* nan or inf */
6305b2ba9d3SPiotr Jasiukajtis if (ix > 0x7f800000)
6315b2ba9d3SPiotr Jasiukajtis return (fx * fx);
6325b2ba9d3SPiotr Jasiukajtis return ((sgn)? -zerof : zerof);
6335b2ba9d3SPiotr Jasiukajtis }
6345b2ba9d3SPiotr Jasiukajtis if ((ix << 1) == 0)
6355b2ba9d3SPiotr Jasiukajtis return ((sgn)? -zerof : zerof);
6365b2ba9d3SPiotr Jasiukajtis
6375b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
6385b2ba9d3SPiotr Jasiukajtis rp = __swapRP(fp_extended);
6395b2ba9d3SPiotr Jasiukajtis #endif
6405b2ba9d3SPiotr Jasiukajtis fx = fabsf(fx);
6415b2ba9d3SPiotr Jasiukajtis x = (double)fx;
6425b2ba9d3SPiotr Jasiukajtis if ((double)n <= x) {
6435b2ba9d3SPiotr Jasiukajtis /* safe to use J(n+1,x) = 2n/x * J(n,x) - J(n-1,x) */
6445b2ba9d3SPiotr Jasiukajtis a = __k_j0f(fx);
6455b2ba9d3SPiotr Jasiukajtis b = __k_j1f(fx);
6465b2ba9d3SPiotr Jasiukajtis for (i = 1; i < n; i++) {
6475b2ba9d3SPiotr Jasiukajtis temp = b;
6485b2ba9d3SPiotr Jasiukajtis b = b * ((double)(i + i) / x) - a;
6495b2ba9d3SPiotr Jasiukajtis a = temp;
6505b2ba9d3SPiotr Jasiukajtis }
6515b2ba9d3SPiotr Jasiukajtis f = (float)b;
6525b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
6535b2ba9d3SPiotr Jasiukajtis if (rp != fp_extended)
6545b2ba9d3SPiotr Jasiukajtis (void) __swapRP(rp);
6555b2ba9d3SPiotr Jasiukajtis #endif
6565b2ba9d3SPiotr Jasiukajtis return ((sgn)? -f : f);
6575b2ba9d3SPiotr Jasiukajtis }
6585b2ba9d3SPiotr Jasiukajtis if (ix < 0x3089705f) {
6595b2ba9d3SPiotr Jasiukajtis /* x < 1.0e-9; use J(n,x) = 1/n! * (x / 2)^n */
6605b2ba9d3SPiotr Jasiukajtis if (n > 6)
6615b2ba9d3SPiotr Jasiukajtis n = 6; /* result underflows to zero for n >= 6 */
6625b2ba9d3SPiotr Jasiukajtis b = t = half * x;
6635b2ba9d3SPiotr Jasiukajtis a = one;
6645b2ba9d3SPiotr Jasiukajtis for (i = 2; i <= n; i++) {
6655b2ba9d3SPiotr Jasiukajtis b *= t;
6665b2ba9d3SPiotr Jasiukajtis a *= (double)i;
6675b2ba9d3SPiotr Jasiukajtis }
6685b2ba9d3SPiotr Jasiukajtis b /= a;
6695b2ba9d3SPiotr Jasiukajtis } else {
6705b2ba9d3SPiotr Jasiukajtis /*
6715b2ba9d3SPiotr Jasiukajtis * Use the backward recurrence:
6725b2ba9d3SPiotr Jasiukajtis *
6735b2ba9d3SPiotr Jasiukajtis * x x^2 x^2
6745b2ba9d3SPiotr Jasiukajtis * J(n,x)/J(n-1,x) = ---- - ------ - ------ .....
6755b2ba9d3SPiotr Jasiukajtis * 2n 2(n+1) 2(n+2)
6765b2ba9d3SPiotr Jasiukajtis *
6775b2ba9d3SPiotr Jasiukajtis * Let w = 2n/x and h = 2/x. Then the above quotient
6785b2ba9d3SPiotr Jasiukajtis * is equal to the continued fraction:
6795b2ba9d3SPiotr Jasiukajtis * 1
6805b2ba9d3SPiotr Jasiukajtis * = -----------------------
6815b2ba9d3SPiotr Jasiukajtis * 1
6825b2ba9d3SPiotr Jasiukajtis * w - -----------------
6835b2ba9d3SPiotr Jasiukajtis * 1
6845b2ba9d3SPiotr Jasiukajtis * w+h - ---------
6855b2ba9d3SPiotr Jasiukajtis * w+2h - ...
6865b2ba9d3SPiotr Jasiukajtis *
6875b2ba9d3SPiotr Jasiukajtis * To determine how many terms are needed, run the
6885b2ba9d3SPiotr Jasiukajtis * recurrence
6895b2ba9d3SPiotr Jasiukajtis *
6905b2ba9d3SPiotr Jasiukajtis * Q(0) = w,
6915b2ba9d3SPiotr Jasiukajtis * Q(1) = w(w+h) - 1,
6925b2ba9d3SPiotr Jasiukajtis * Q(k) = (w+k*h)*Q(k-1) - Q(k-2).
6935b2ba9d3SPiotr Jasiukajtis *
6945b2ba9d3SPiotr Jasiukajtis * Then when Q(k) > 1e4, k is large enough for single
6955b2ba9d3SPiotr Jasiukajtis * precision.
6965b2ba9d3SPiotr Jasiukajtis */
6975b2ba9d3SPiotr Jasiukajtis /* XXX NOT DONE - rework this */
6985b2ba9d3SPiotr Jasiukajtis w = (n + n) / x;
6995b2ba9d3SPiotr Jasiukajtis h = two / x;
7005b2ba9d3SPiotr Jasiukajtis q0 = w;
7015b2ba9d3SPiotr Jasiukajtis z = w + h;
7025b2ba9d3SPiotr Jasiukajtis q1 = w * z - one;
7035b2ba9d3SPiotr Jasiukajtis k = 1;
7045b2ba9d3SPiotr Jasiukajtis while (q1 < big) {
7055b2ba9d3SPiotr Jasiukajtis k++;
7065b2ba9d3SPiotr Jasiukajtis z += h;
7075b2ba9d3SPiotr Jasiukajtis temp = z * q1 - q0;
7085b2ba9d3SPiotr Jasiukajtis q0 = q1;
7095b2ba9d3SPiotr Jasiukajtis q1 = temp;
7105b2ba9d3SPiotr Jasiukajtis }
7115b2ba9d3SPiotr Jasiukajtis m = n + n;
7125b2ba9d3SPiotr Jasiukajtis t = zero;
7135b2ba9d3SPiotr Jasiukajtis for (i = (n + k) << 1; i >= m; i -= 2)
7145b2ba9d3SPiotr Jasiukajtis t = one / ((double)i / x - t);
7155b2ba9d3SPiotr Jasiukajtis a = t;
7165b2ba9d3SPiotr Jasiukajtis b = one;
7175b2ba9d3SPiotr Jasiukajtis /*
7185b2ba9d3SPiotr Jasiukajtis * estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
7195b2ba9d3SPiotr Jasiukajtis * hence, if n*(log(2n/x)) > ...
7205b2ba9d3SPiotr Jasiukajtis * single 8.8722839355e+01
7215b2ba9d3SPiotr Jasiukajtis * double 7.09782712893383973096e+02
7225b2ba9d3SPiotr Jasiukajtis * then recurrent value may overflow and the result is
7235b2ba9d3SPiotr Jasiukajtis * likely underflow to zero
7245b2ba9d3SPiotr Jasiukajtis */
7255b2ba9d3SPiotr Jasiukajtis temp = (double)n;
7265b2ba9d3SPiotr Jasiukajtis temp *= log((two / x) * temp);
7275b2ba9d3SPiotr Jasiukajtis if (temp < 7.09782712893383973096e+02) {
7285b2ba9d3SPiotr Jasiukajtis for (i = n - 1; i > 0; i--) {
7295b2ba9d3SPiotr Jasiukajtis temp = b;
7305b2ba9d3SPiotr Jasiukajtis b = b * ((double)(i + i) / x) - a;
7315b2ba9d3SPiotr Jasiukajtis a = temp;
7325b2ba9d3SPiotr Jasiukajtis }
7335b2ba9d3SPiotr Jasiukajtis } else {
7345b2ba9d3SPiotr Jasiukajtis for (i = n - 1; i > 0; i--) {
7355b2ba9d3SPiotr Jasiukajtis temp = b;
7365b2ba9d3SPiotr Jasiukajtis b = b * ((double)(i + i) / x) - a;
7375b2ba9d3SPiotr Jasiukajtis a = temp;
7385b2ba9d3SPiotr Jasiukajtis if (b > 1.0e100) {
7395b2ba9d3SPiotr Jasiukajtis a /= b;
7405b2ba9d3SPiotr Jasiukajtis t /= b;
7415b2ba9d3SPiotr Jasiukajtis b = one;
7425b2ba9d3SPiotr Jasiukajtis }
7435b2ba9d3SPiotr Jasiukajtis }
7445b2ba9d3SPiotr Jasiukajtis }
7455b2ba9d3SPiotr Jasiukajtis b = (t * __k_j0f(fx) / b);
7465b2ba9d3SPiotr Jasiukajtis }
7475b2ba9d3SPiotr Jasiukajtis f = (float)b;
7485b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
7495b2ba9d3SPiotr Jasiukajtis if (rp != fp_extended)
7505b2ba9d3SPiotr Jasiukajtis (void) __swapRP(rp);
7515b2ba9d3SPiotr Jasiukajtis #endif
7525b2ba9d3SPiotr Jasiukajtis return ((sgn)? -f : f);
7535b2ba9d3SPiotr Jasiukajtis }
7545b2ba9d3SPiotr Jasiukajtis
7555b2ba9d3SPiotr Jasiukajtis float
ynf(int n,float fx)7565b2ba9d3SPiotr Jasiukajtis ynf(int n, float fx)
7575b2ba9d3SPiotr Jasiukajtis {
7585b2ba9d3SPiotr Jasiukajtis double a, b, temp, x;
7595b2ba9d3SPiotr Jasiukajtis float f;
7605b2ba9d3SPiotr Jasiukajtis int i, sign, ix;
7615b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
7625b2ba9d3SPiotr Jasiukajtis int rp;
7635b2ba9d3SPiotr Jasiukajtis #endif
7645b2ba9d3SPiotr Jasiukajtis
7655b2ba9d3SPiotr Jasiukajtis sign = 0;
7665b2ba9d3SPiotr Jasiukajtis if (n < 0) {
7675b2ba9d3SPiotr Jasiukajtis n = -n;
7685b2ba9d3SPiotr Jasiukajtis if (n & 1)
7695b2ba9d3SPiotr Jasiukajtis sign = 1;
7705b2ba9d3SPiotr Jasiukajtis }
7715b2ba9d3SPiotr Jasiukajtis if (n == 0)
7725b2ba9d3SPiotr Jasiukajtis return (y0f(fx));
7735b2ba9d3SPiotr Jasiukajtis if (n == 1)
7745b2ba9d3SPiotr Jasiukajtis return ((sign)? -y1f(fx) : y1f(fx));
7755b2ba9d3SPiotr Jasiukajtis
7765b2ba9d3SPiotr Jasiukajtis ix = *(int *)&fx;
7775b2ba9d3SPiotr Jasiukajtis if ((ix & ~0x80000000) > 0x7f800000) /* nan */
7785b2ba9d3SPiotr Jasiukajtis return (fx * fx);
7795b2ba9d3SPiotr Jasiukajtis if (ix <= 0) { /* zero or negative */
7805b2ba9d3SPiotr Jasiukajtis if ((ix << 1) == 0)
7815b2ba9d3SPiotr Jasiukajtis return (-onef / zerof);
7825b2ba9d3SPiotr Jasiukajtis return (zerof / zerof);
7835b2ba9d3SPiotr Jasiukajtis }
7845b2ba9d3SPiotr Jasiukajtis if (ix == 0x7f800000) /* +inf */
7855b2ba9d3SPiotr Jasiukajtis return (zerof);
7865b2ba9d3SPiotr Jasiukajtis
7875b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
7885b2ba9d3SPiotr Jasiukajtis rp = __swapRP(fp_extended);
7895b2ba9d3SPiotr Jasiukajtis #endif
7905b2ba9d3SPiotr Jasiukajtis a = __k_y0f(fx);
7915b2ba9d3SPiotr Jasiukajtis b = __k_y1f(fx);
7925b2ba9d3SPiotr Jasiukajtis x = (double)fx;
7935b2ba9d3SPiotr Jasiukajtis for (i = 1; i < n; i++) {
7945b2ba9d3SPiotr Jasiukajtis temp = b;
7955b2ba9d3SPiotr Jasiukajtis b *= (double)(i + i) / x;
7965b2ba9d3SPiotr Jasiukajtis if (b <= -DBL_MAX)
7975b2ba9d3SPiotr Jasiukajtis break;
7985b2ba9d3SPiotr Jasiukajtis b -= a;
7995b2ba9d3SPiotr Jasiukajtis a = temp;
8005b2ba9d3SPiotr Jasiukajtis }
8015b2ba9d3SPiotr Jasiukajtis f = (float)b;
8025b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
8035b2ba9d3SPiotr Jasiukajtis if (rp != fp_extended)
8045b2ba9d3SPiotr Jasiukajtis (void) __swapRP(rp);
8055b2ba9d3SPiotr Jasiukajtis #endif
8065b2ba9d3SPiotr Jasiukajtis return ((sign)? -f : f);
8075b2ba9d3SPiotr Jasiukajtis }
808