blob: e24700cfbf2752617cd28910ebf00b5918f4ae75 [file] [log] [blame]
Kai Tietz518dd332007-08-10 09:54:15 +00001#include "cephes_mconf.h"
2#ifndef _SET_ERRNO
3#define _SET_ERRNO(x)
4#endif
5
6
7/* Table size */
8#define NXT 32
9/* log2(Table size) */
10#define LNXT 5
11
12#ifdef UNK
13/* log(1+x) = x - .5x^2 + x^3 * P(z)/Q(z)
14 * on the domain 2^(-1/32) - 1 <= x <= 2^(1/32) - 1
15 */
16static long double P[] = {
17 8.3319510773868690346226E-4L,
18 4.9000050881978028599627E-1L,
19 1.7500123722550302671919E0L,
20 1.4000100839971580279335E0L,
21};
22static long double Q[] = {
23/* 1.0000000000000000000000E0L,*/
24 5.2500282295834889175431E0L,
25 8.4000598057587009834666E0L,
26 4.2000302519914740834728E0L,
27};
28/* A[i] = 2^(-i/32), rounded to IEEE long double precision.
29 * If i is even, A[i] + B[i/2] gives additional accuracy.
30 */
31static long double A[33] = {
32 1.0000000000000000000000E0L,
33 9.7857206208770013448287E-1L,
34 9.5760328069857364691013E-1L,
35 9.3708381705514995065011E-1L,
36 9.1700404320467123175367E-1L,
37 8.9735453750155359320742E-1L,
38 8.7812608018664974155474E-1L,
39 8.5930964906123895780165E-1L,
40 8.4089641525371454301892E-1L,
41 8.2287773907698242225554E-1L,
42 8.0524516597462715409607E-1L,
43 7.8799042255394324325455E-1L,
44 7.7110541270397041179298E-1L,
45 7.5458221379671136985669E-1L,
46 7.3841307296974965571198E-1L,
47 7.2259040348852331001267E-1L,
48 7.0710678118654752438189E-1L,
49 6.9195494098191597746178E-1L,
50 6.7712777346844636413344E-1L,
51 6.6261832157987064729696E-1L,
52 6.4841977732550483296079E-1L,
53 6.3452547859586661129850E-1L,
54 6.2092890603674202431705E-1L,
55 6.0762367999023443907803E-1L,
56 5.9460355750136053334378E-1L,
57 5.8186242938878875689693E-1L,
58 5.6939431737834582684856E-1L,
59 5.5719337129794626814472E-1L,
60 5.4525386633262882960438E-1L,
61 5.3357020033841180906486E-1L,
62 5.2213689121370692017331E-1L,
63 5.1094857432705833910408E-1L,
64 5.0000000000000000000000E-1L,
65};
66static long double B[17] = {
67 0.0000000000000000000000E0L,
68 2.6176170809902549338711E-20L,
69-1.0126791927256478897086E-20L,
70 1.3438228172316276937655E-21L,
71 1.2207982955417546912101E-20L,
72-6.3084814358060867200133E-21L,
73 1.3164426894366316434230E-20L,
74-1.8527916071632873716786E-20L,
75 1.8950325588932570796551E-20L,
76 1.5564775779538780478155E-20L,
77 6.0859793637556860974380E-21L,
78-2.0208749253662532228949E-20L,
79 1.4966292219224761844552E-20L,
80 3.3540909728056476875639E-21L,
81-8.6987564101742849540743E-22L,
82-1.2327176863327626135542E-20L,
83 0.0000000000000000000000E0L,
84};
85
86/* 2^x = 1 + x P(x),
87 * on the interval -1/32 <= x <= 0
88 */
89static long double R[] = {
90 1.5089970579127659901157E-5L,
91 1.5402715328927013076125E-4L,
92 1.3333556028915671091390E-3L,
93 9.6181291046036762031786E-3L,
94 5.5504108664798463044015E-2L,
95 2.4022650695910062854352E-1L,
96 6.9314718055994530931447E-1L,
97};
98
99#define douba(k) A[k]
100#define doubb(k) B[k]
101#define MEXP (NXT*16384.0L)
102/* The following if denormal numbers are supported, else -MEXP: */
103#ifdef DENORMAL
104#define MNEXP (-NXT*(16384.0L+64.0L))
105#else
106#define MNEXP (-NXT*16384.0L)
107#endif
108/* log2(e) - 1 */
109#define LOG2EA 0.44269504088896340735992L
110#endif
111
112
113#ifdef IBMPC
114static const unsigned short P[] = {
1150xb804,0xa8b7,0xc6f4,0xda6a,0x3ff4, XPD
1160x7de9,0xcf02,0x58c0,0xfae1,0x3ffd, XPD
1170x405a,0x3722,0x67c9,0xe000,0x3fff, XPD
1180xcd99,0x6b43,0x87ca,0xb333,0x3fff, XPD
119};
120static const unsigned short Q[] = {
121/* 0x0000,0x0000,0x0000,0x8000,0x3fff, */
1220x6307,0xa469,0x3b33,0xa800,0x4001, XPD
1230xfec2,0x62d7,0xa51c,0x8666,0x4002, XPD
1240xda32,0xd072,0xa5d7,0x8666,0x4001, XPD
125};
126static const unsigned short A[] = {
1270x0000,0x0000,0x0000,0x8000,0x3fff, XPD
1280x033a,0x722a,0xb2db,0xfa83,0x3ffe, XPD
1290xcc2c,0x2486,0x7d15,0xf525,0x3ffe, XPD
1300xf5cb,0xdcda,0xb99b,0xefe4,0x3ffe, XPD
1310x392f,0xdd24,0xc6e7,0xeac0,0x3ffe, XPD
1320x48a8,0x7c83,0x06e7,0xe5b9,0x3ffe, XPD
1330xe111,0x2a94,0xdeec,0xe0cc,0x3ffe, XPD
1340x3755,0xdaf2,0xb797,0xdbfb,0x3ffe, XPD
1350x6af4,0xd69d,0xfcca,0xd744,0x3ffe, XPD
1360xe45a,0xf12a,0x1d91,0xd2a8,0x3ffe, XPD
1370x80e4,0x1f84,0x8c15,0xce24,0x3ffe, XPD
1380x27a3,0x6e2f,0xbd86,0xc9b9,0x3ffe, XPD
1390xdadd,0x5506,0x2a11,0xc567,0x3ffe, XPD
1400x9456,0x6670,0x4cca,0xc12c,0x3ffe, XPD
1410x36bf,0x580c,0xa39f,0xbd08,0x3ffe, XPD
1420x9ee9,0x62fb,0xaf47,0xb8fb,0x3ffe, XPD
1430x6484,0xf9de,0xf333,0xb504,0x3ffe, XPD
1440x2590,0xd2ac,0xf581,0xb123,0x3ffe, XPD
1450x4ac6,0x42a1,0x3eea,0xad58,0x3ffe, XPD
1460x0ef8,0xea7c,0x5ab4,0xa9a1,0x3ffe, XPD
1470x38ea,0xb151,0xd6a9,0xa5fe,0x3ffe, XPD
1480x6819,0x0c49,0x4303,0xa270,0x3ffe, XPD
1490x11ae,0x91a1,0x3260,0x9ef5,0x3ffe, XPD
1500x5539,0xd54e,0x39b9,0x9b8d,0x3ffe, XPD
1510xa96f,0x8db8,0xf051,0x9837,0x3ffe, XPD
1520x0961,0xfef7,0xefa8,0x94f4,0x3ffe, XPD
1530xc336,0xab11,0xd373,0x91c3,0x3ffe, XPD
1540x53c0,0x45cd,0x398b,0x8ea4,0x3ffe, XPD
1550xd6e7,0xea8b,0xc1e3,0x8b95,0x3ffe, XPD
1560x8527,0x92da,0x0e80,0x8898,0x3ffe, XPD
1570x7b15,0xcc48,0xc367,0x85aa,0x3ffe, XPD
1580xa1d7,0xac2b,0x8698,0x82cd,0x3ffe, XPD
1590x0000,0x0000,0x0000,0x8000,0x3ffe, XPD
160};
161static const unsigned short B[] = {
1620x0000,0x0000,0x0000,0x0000,0x0000, XPD
1630x1f87,0xdb30,0x18f5,0xf73a,0x3fbd, XPD
1640xac15,0x3e46,0x2932,0xbf4a,0xbfbc, XPD
1650x7944,0xba66,0xa091,0xcb12,0x3fb9, XPD
1660xff78,0x40b4,0x2ee6,0xe69a,0x3fbc, XPD
1670xc895,0x5069,0xe383,0xee53,0xbfbb, XPD
1680x7cde,0x9376,0x4325,0xf8ab,0x3fbc, XPD
1690xa10c,0x25e0,0xc093,0xaefd,0xbfbd, XPD
1700x7d3e,0xea95,0x1366,0xb2fb,0x3fbd, XPD
1710x5d89,0xeb34,0x5191,0x9301,0x3fbd, XPD
1720x80d9,0xb883,0xfb10,0xe5eb,0x3fbb, XPD
1730x045d,0x288c,0xc1ec,0xbedd,0xbfbd, XPD
1740xeded,0x5c85,0x4630,0x8d5a,0x3fbd, XPD
1750x9d82,0xe5ac,0x8e0a,0xfd6d,0x3fba, XPD
1760x6dfd,0xeb58,0xaf14,0x8373,0xbfb9, XPD
1770xf938,0x7aac,0x91cf,0xe8da,0xbfbc, XPD
1780x0000,0x0000,0x0000,0x0000,0x0000, XPD
179};
180static const unsigned short R[] = {
1810xa69b,0x530e,0xee1d,0xfd2a,0x3fee, XPD
1820xc746,0x8e7e,0x5960,0xa182,0x3ff2, XPD
1830x63b6,0xadda,0xfd6a,0xaec3,0x3ff5, XPD
1840xc104,0xfd99,0x5b7c,0x9d95,0x3ff8, XPD
1850xe05e,0x249d,0x46b8,0xe358,0x3ffa, XPD
1860x5d1d,0x162c,0xeffc,0xf5fd,0x3ffc, XPD
1870x79aa,0xd1cf,0x17f7,0xb172,0x3ffe, XPD
188};
189
190/* 10 byte sizes versus 12 byte */
191#define douba(k) (*(long double *)(&A[(sizeof( long double )/2)*(k)]))
192#define doubb(k) (*(long double *)(&B[(sizeof( long double )/2)*(k)]))
193#define MEXP (NXT*16384.0L)
194#ifdef DENORMAL
195#define MNEXP (-NXT*(16384.0L+64.0L))
196#else
197#define MNEXP (-NXT*16384.0L)
198#endif
199static const
200union
201{
202 unsigned short L[6];
203 long double ld;
204} log2ea = {{0xc2ef,0x705f,0xeca5,0xe2a8,0x3ffd, XPD}};
205
206#define LOG2EA (log2ea.ld)
207/*
208#define LOG2EA 0.44269504088896340735992L
209*/
210#endif
211
212#ifdef MIEEE
213static long P[] = {
2140x3ff40000,0xda6ac6f4,0xa8b7b804,
2150x3ffd0000,0xfae158c0,0xcf027de9,
2160x3fff0000,0xe00067c9,0x3722405a,
2170x3fff0000,0xb33387ca,0x6b43cd99,
218};
219static long Q[] = {
220/* 0x3fff0000,0x80000000,0x00000000, */
2210x40010000,0xa8003b33,0xa4696307,
2220x40020000,0x8666a51c,0x62d7fec2,
2230x40010000,0x8666a5d7,0xd072da32,
224};
225static long A[] = {
2260x3fff0000,0x80000000,0x00000000,
2270x3ffe0000,0xfa83b2db,0x722a033a,
2280x3ffe0000,0xf5257d15,0x2486cc2c,
2290x3ffe0000,0xefe4b99b,0xdcdaf5cb,
2300x3ffe0000,0xeac0c6e7,0xdd24392f,
2310x3ffe0000,0xe5b906e7,0x7c8348a8,
2320x3ffe0000,0xe0ccdeec,0x2a94e111,
2330x3ffe0000,0xdbfbb797,0xdaf23755,
2340x3ffe0000,0xd744fcca,0xd69d6af4,
2350x3ffe0000,0xd2a81d91,0xf12ae45a,
2360x3ffe0000,0xce248c15,0x1f8480e4,
2370x3ffe0000,0xc9b9bd86,0x6e2f27a3,
2380x3ffe0000,0xc5672a11,0x5506dadd,
2390x3ffe0000,0xc12c4cca,0x66709456,
2400x3ffe0000,0xbd08a39f,0x580c36bf,
2410x3ffe0000,0xb8fbaf47,0x62fb9ee9,
2420x3ffe0000,0xb504f333,0xf9de6484,
2430x3ffe0000,0xb123f581,0xd2ac2590,
2440x3ffe0000,0xad583eea,0x42a14ac6,
2450x3ffe0000,0xa9a15ab4,0xea7c0ef8,
2460x3ffe0000,0xa5fed6a9,0xb15138ea,
2470x3ffe0000,0xa2704303,0x0c496819,
2480x3ffe0000,0x9ef53260,0x91a111ae,
2490x3ffe0000,0x9b8d39b9,0xd54e5539,
2500x3ffe0000,0x9837f051,0x8db8a96f,
2510x3ffe0000,0x94f4efa8,0xfef70961,
2520x3ffe0000,0x91c3d373,0xab11c336,
2530x3ffe0000,0x8ea4398b,0x45cd53c0,
2540x3ffe0000,0x8b95c1e3,0xea8bd6e7,
2550x3ffe0000,0x88980e80,0x92da8527,
2560x3ffe0000,0x85aac367,0xcc487b15,
2570x3ffe0000,0x82cd8698,0xac2ba1d7,
2580x3ffe0000,0x80000000,0x00000000,
259};
260static long B[51] = {
2610x00000000,0x00000000,0x00000000,
2620x3fbd0000,0xf73a18f5,0xdb301f87,
2630xbfbc0000,0xbf4a2932,0x3e46ac15,
2640x3fb90000,0xcb12a091,0xba667944,
2650x3fbc0000,0xe69a2ee6,0x40b4ff78,
2660xbfbb0000,0xee53e383,0x5069c895,
2670x3fbc0000,0xf8ab4325,0x93767cde,
2680xbfbd0000,0xaefdc093,0x25e0a10c,
2690x3fbd0000,0xb2fb1366,0xea957d3e,
2700x3fbd0000,0x93015191,0xeb345d89,
2710x3fbb0000,0xe5ebfb10,0xb88380d9,
2720xbfbd0000,0xbeddc1ec,0x288c045d,
2730x3fbd0000,0x8d5a4630,0x5c85eded,
2740x3fba0000,0xfd6d8e0a,0xe5ac9d82,
2750xbfb90000,0x8373af14,0xeb586dfd,
2760xbfbc0000,0xe8da91cf,0x7aacf938,
2770x00000000,0x00000000,0x00000000,
278};
279static long R[] = {
2800x3fee0000,0xfd2aee1d,0x530ea69b,
2810x3ff20000,0xa1825960,0x8e7ec746,
2820x3ff50000,0xaec3fd6a,0xadda63b6,
2830x3ff80000,0x9d955b7c,0xfd99c104,
2840x3ffa0000,0xe35846b8,0x249de05e,
2850x3ffc0000,0xf5fdeffc,0x162c5d1d,
2860x3ffe0000,0xb17217f7,0xd1cf79aa,
287};
288
289#define douba(k) (*(long double *)&A[3*(k)])
290#define doubb(k) (*(long double *)&B[3*(k)])
291#define MEXP (NXT*16384.0L)
292#ifdef DENORMAL
293#define MNEXP (-NXT*(16384.0L+64.0L))
294#else
295#define MNEXP (-NXT*16382.0L)
296#endif
297static long L[3] = {0x3ffd0000,0xe2a8eca5,0x705fc2ef};
298#define LOG2EA (*(long double *)(&L[0]))
299#endif
300
301
302#define F W
303#define Fa Wa
304#define Fb Wb
305#define G W
306#define Ga Wa
307#define Gb u
308#define H W
309#define Ha Wb
310#define Hb Wb
311
312static VOLATILE long double z;
313static long double w, W, Wa, Wb, ya, yb, u;
314
315static __inline__ long double reducl( long double );
316extern long double __powil ( long double, int );
317extern long double powl ( long double x, long double y);
318
319/* No error checking. We handle Infs and zeros ourselves. */
320static __inline__ long double
321__fast_ldexpl (long double x, int expn)
322{
323 long double res;
324 __asm__ ("fscale"
325 : "=t" (res)
326 : "0" (x), "u" ((long double) expn));
327 return res;
328}
329
330#define ldexpl __fast_ldexpl
331
332long double powl( x, y )
333long double x, y;
334{
335/* double F, Fa, Fb, G, Ga, Gb, H, Ha, Hb */
336int i, nflg, iyflg, yoddint;
337long e;
338
339if( y == 0.0L )
340 return( 1.0L );
341
342#ifdef NANS
343if( isnanl(x) )
344 {
345 _SET_ERRNO (EDOM);
346 return( x );
347 }
348if( isnanl(y) )
349 {
350 _SET_ERRNO (EDOM);
351 return( y );
352 }
353#endif
354
355if( y == 1.0L )
356 return( x );
357
358if( isinfl(y) && (x == -1.0L || x == 1.0L) )
359 return( y );
360
361if( x == 1.0L )
362 return( 1.0L );
363
364if( y >= MAXNUML )
365 {
366 _SET_ERRNO (ERANGE);
367#ifdef INFINITIES
368 if( x > 1.0L )
369 return( INFINITYL );
370#else
371 if( x > 1.0L )
372 return( MAXNUML );
373#endif
374 if( x > 0.0L && x < 1.0L )
375 return( 0.0L );
376#ifdef INFINITIES
377 if( x < -1.0L )
378 return( INFINITYL );
379#else
380 if( x < -1.0L )
381 return( MAXNUML );
382#endif
383 if( x > -1.0L && x < 0.0L )
384 return( 0.0L );
385 }
386if( y <= -MAXNUML )
387 {
388 _SET_ERRNO (ERANGE);
389 if( x > 1.0L )
390 return( 0.0L );
391#ifdef INFINITIES
392 if( x > 0.0L && x < 1.0L )
393 return( INFINITYL );
394#else
395 if( x > 0.0L && x < 1.0L )
396 return( MAXNUML );
397#endif
398 if( x < -1.0L )
399 return( 0.0L );
400#ifdef INFINITIES
401 if( x > -1.0L && x < 0.0L )
402 return( INFINITYL );
403#else
404 if( x > -1.0L && x < 0.0L )
405 return( MAXNUML );
406#endif
407 }
408if( x >= MAXNUML )
409 {
410#if INFINITIES
411 if( y > 0.0L )
412 return( INFINITYL );
413#else
414 if( y > 0.0L )
415 return( MAXNUML );
416#endif
417 return( 0.0L );
418 }
419
420w = floorl(y);
421/* Set iyflg to 1 if y is an integer. */
422iyflg = 0;
423if( w == y )
424 iyflg = 1;
425
426/* Test for odd integer y. */
427yoddint = 0;
428if( iyflg )
429 {
430 ya = fabsl(y);
431 ya = floorl(0.5L * ya);
432 yb = 0.5L * fabsl(w);
433 if( ya != yb )
434 yoddint = 1;
435 }
436
437if( x <= -MAXNUML )
438 {
439 if( y > 0.0L )
440 {
441#ifdef INFINITIES
442 if( yoddint )
443 return( -INFINITYL );
444 return( INFINITYL );
445#else
446 if( yoddint )
447 return( -MAXNUML );
448 return( MAXNUML );
449#endif
450 }
451 if( y < 0.0L )
452 {
453#ifdef MINUSZERO
454 if( yoddint )
455 return( NEGZEROL );
456#endif
457 return( 0.0 );
458 }
459 }
460
461
462nflg = 0; /* flag = 1 if x<0 raised to integer power */
463if( x <= 0.0L )
464 {
465 if( x == 0.0L )
466 {
467 if( y < 0.0 )
468 {
469#ifdef MINUSZERO
470 if( signbitl(x) && yoddint )
471 return( -INFINITYL );
472#endif
473#ifdef INFINITIES
474 return( INFINITYL );
475#else
476 return( MAXNUML );
477#endif
478 }
479 if( y > 0.0 )
480 {
481#ifdef MINUSZERO
482 if( signbitl(x) && yoddint )
483 return( NEGZEROL );
484#endif
485 return( 0.0 );
486 }
487 if( y == 0.0L )
488 return( 1.0L ); /* 0**0 */
489 else
490 return( 0.0L ); /* 0**y */
491 }
492 else
493 {
494 if( iyflg == 0 )
495 { /* noninteger power of negative number */
496 mtherr( fname, DOMAIN );
497 _SET_ERRNO (EDOM);
498#ifdef NANS
499 return(NANL);
500#else
501 return(0.0L);
502#endif
503 }
504 nflg = 1;
505 }
506 }
507
508/* Integer power of an integer. */
509
510if( iyflg )
511 {
512 i = w;
513 w = floorl(x);
514 if( (w == x) && (fabsl(y) < 32768.0) )
515 {
516 w = __powil( x, (int) y );
517 return( w );
518 }
519 }
520
521
522if( nflg )
523 x = fabsl(x);
524
525/* separate significand from exponent */
526x = frexpl( x, &i );
527e = i;
528
529/* find significand in antilog table A[] */
530i = 1;
531if( x <= douba(17) )
532 i = 17;
533if( x <= douba(i+8) )
534 i += 8;
535if( x <= douba(i+4) )
536 i += 4;
537if( x <= douba(i+2) )
538 i += 2;
539if( x >= douba(1) )
540 i = -1;
541i += 1;
542
543
544/* Find (x - A[i])/A[i]
545 * in order to compute log(x/A[i]):
546 *
547 * log(x) = log( a x/a ) = log(a) + log(x/a)
548 *
549 * log(x/a) = log(1+v), v = x/a - 1 = (x-a)/a
550 */
551x -= douba(i);
552x -= doubb(i/2);
553x /= douba(i);
554
555
556/* rational approximation for log(1+v):
557 *
558 * log(1+v) = v - v**2/2 + v**3 P(v) / Q(v)
559 */
560z = x*x;
561w = x * ( z * polevll( x, P, 3 ) / p1evll( x, Q, 3 ) );
562w = w - ldexpl( z, -1 ); /* w - 0.5 * z */
563
564/* Convert to base 2 logarithm:
565 * multiply by log2(e) = 1 + LOG2EA
566 */
567z = LOG2EA * w;
568z += w;
569z += LOG2EA * x;
570z += x;
571
572/* Compute exponent term of the base 2 logarithm. */
573w = -i;
574w = ldexpl( w, -LNXT ); /* divide by NXT */
575w += e;
576/* Now base 2 log of x is w + z. */
577
578/* Multiply base 2 log by y, in extended precision. */
579
580/* separate y into large part ya
581 * and small part yb less than 1/NXT
582 */
583ya = reducl(y);
584yb = y - ya;
585
586/* (w+z)(ya+yb)
587 * = w*ya + w*yb + z*y
588 */
589F = z * y + w * yb;
590Fa = reducl(F);
591Fb = F - Fa;
592
593G = Fa + w * ya;
594Ga = reducl(G);
595Gb = G - Ga;
596
597H = Fb + Gb;
598Ha = reducl(H);
599w = ldexpl( Ga + Ha, LNXT );
600
601/* Test the power of 2 for overflow */
602if( w > MEXP )
603 {
604 _SET_ERRNO (ERANGE);
605 mtherr( fname, OVERFLOW );
606 return( MAXNUML );
607 }
608
609if( w < MNEXP )
610 {
611 _SET_ERRNO (ERANGE);
612 mtherr( fname, UNDERFLOW );
613 return( 0.0L );
614 }
615
616e = w;
617Hb = H - Ha;
618
619if( Hb > 0.0L )
620 {
621 e += 1;
622 Hb -= (1.0L/NXT); /*0.0625L;*/
623 }
624
625/* Now the product y * log2(x) = Hb + e/NXT.
626 *
627 * Compute base 2 exponential of Hb,
628 * where -0.0625 <= Hb <= 0.
629 */
630z = Hb * polevll( Hb, R, 6 ); /* z = 2**Hb - 1 */
631
632/* Express e/NXT as an integer plus a negative number of (1/NXT)ths.
633 * Find lookup table entry for the fractional power of 2.
634 */
635if( e < 0 )
636 i = 0;
637else
638 i = 1;
639i = e/NXT + i;
640e = NXT*i - e;
641w = douba( e );
642z = w * z; /* 2**-e * ( 1 + (2**Hb-1) ) */
643z = z + w;
644z = ldexpl( z, i ); /* multiply by integer power of 2 */
645
646if( nflg )
647 {
648/* For negative x,
649 * find out if the integer exponent
650 * is odd or even.
651 */
652 w = ldexpl( y, -1 );
653 w = floorl(w);
654 w = ldexpl( w, 1 );
655 if( w != y )
656 z = -z; /* odd exponent */
657 }
658
659return( z );
660}
661
662static __inline__ long double
663__convert_inf_to_maxnum(long double x)
664{
665 if (isinf(x))
666 return (x > 0.0L ? MAXNUML : -MAXNUML);
667 else
668 return x;
669}
670
671
672/* Find a multiple of 1/NXT that is within 1/NXT of x. */
673static __inline__ long double reducl(x)
674long double x;
675{
676long double t;
677
678/* If the call to ldexpl overflows, set it to MAXNUML.
679 This avoids Inf - Inf = Nan result when calculating the 'small'
680 part of a reduction. Instead, the small part becomes Inf,
681 causing under/overflow when adding it to the 'large' part.
682 There must be a cleaner way of doing this. */
683t = __convert_inf_to_maxnum (ldexpl( x, LNXT ));
684t = floorl( t );
685t = ldexpl( t, -LNXT );
686return(t);
687}