Kai Tietz | 518dd33 | 2007-08-10 09:54:15 +0000 | [diff] [blame^] | 1 | #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 | */
|
| 16 | static long double P[] = {
|
| 17 | 8.3319510773868690346226E-4L,
|
| 18 | 4.9000050881978028599627E-1L,
|
| 19 | 1.7500123722550302671919E0L,
|
| 20 | 1.4000100839971580279335E0L,
|
| 21 | };
|
| 22 | static 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 | */
|
| 31 | static 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 | };
|
| 66 | static 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 | */
|
| 89 | static 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
|
| 114 | static const unsigned short P[] = {
|
| 115 | 0xb804,0xa8b7,0xc6f4,0xda6a,0x3ff4, XPD
|
| 116 | 0x7de9,0xcf02,0x58c0,0xfae1,0x3ffd, XPD
|
| 117 | 0x405a,0x3722,0x67c9,0xe000,0x3fff, XPD
|
| 118 | 0xcd99,0x6b43,0x87ca,0xb333,0x3fff, XPD
|
| 119 | };
|
| 120 | static const unsigned short Q[] = {
|
| 121 | /* 0x0000,0x0000,0x0000,0x8000,0x3fff, */
|
| 122 | 0x6307,0xa469,0x3b33,0xa800,0x4001, XPD
|
| 123 | 0xfec2,0x62d7,0xa51c,0x8666,0x4002, XPD
|
| 124 | 0xda32,0xd072,0xa5d7,0x8666,0x4001, XPD
|
| 125 | };
|
| 126 | static const unsigned short A[] = {
|
| 127 | 0x0000,0x0000,0x0000,0x8000,0x3fff, XPD
|
| 128 | 0x033a,0x722a,0xb2db,0xfa83,0x3ffe, XPD
|
| 129 | 0xcc2c,0x2486,0x7d15,0xf525,0x3ffe, XPD
|
| 130 | 0xf5cb,0xdcda,0xb99b,0xefe4,0x3ffe, XPD
|
| 131 | 0x392f,0xdd24,0xc6e7,0xeac0,0x3ffe, XPD
|
| 132 | 0x48a8,0x7c83,0x06e7,0xe5b9,0x3ffe, XPD
|
| 133 | 0xe111,0x2a94,0xdeec,0xe0cc,0x3ffe, XPD
|
| 134 | 0x3755,0xdaf2,0xb797,0xdbfb,0x3ffe, XPD
|
| 135 | 0x6af4,0xd69d,0xfcca,0xd744,0x3ffe, XPD
|
| 136 | 0xe45a,0xf12a,0x1d91,0xd2a8,0x3ffe, XPD
|
| 137 | 0x80e4,0x1f84,0x8c15,0xce24,0x3ffe, XPD
|
| 138 | 0x27a3,0x6e2f,0xbd86,0xc9b9,0x3ffe, XPD
|
| 139 | 0xdadd,0x5506,0x2a11,0xc567,0x3ffe, XPD
|
| 140 | 0x9456,0x6670,0x4cca,0xc12c,0x3ffe, XPD
|
| 141 | 0x36bf,0x580c,0xa39f,0xbd08,0x3ffe, XPD
|
| 142 | 0x9ee9,0x62fb,0xaf47,0xb8fb,0x3ffe, XPD
|
| 143 | 0x6484,0xf9de,0xf333,0xb504,0x3ffe, XPD
|
| 144 | 0x2590,0xd2ac,0xf581,0xb123,0x3ffe, XPD
|
| 145 | 0x4ac6,0x42a1,0x3eea,0xad58,0x3ffe, XPD
|
| 146 | 0x0ef8,0xea7c,0x5ab4,0xa9a1,0x3ffe, XPD
|
| 147 | 0x38ea,0xb151,0xd6a9,0xa5fe,0x3ffe, XPD
|
| 148 | 0x6819,0x0c49,0x4303,0xa270,0x3ffe, XPD
|
| 149 | 0x11ae,0x91a1,0x3260,0x9ef5,0x3ffe, XPD
|
| 150 | 0x5539,0xd54e,0x39b9,0x9b8d,0x3ffe, XPD
|
| 151 | 0xa96f,0x8db8,0xf051,0x9837,0x3ffe, XPD
|
| 152 | 0x0961,0xfef7,0xefa8,0x94f4,0x3ffe, XPD
|
| 153 | 0xc336,0xab11,0xd373,0x91c3,0x3ffe, XPD
|
| 154 | 0x53c0,0x45cd,0x398b,0x8ea4,0x3ffe, XPD
|
| 155 | 0xd6e7,0xea8b,0xc1e3,0x8b95,0x3ffe, XPD
|
| 156 | 0x8527,0x92da,0x0e80,0x8898,0x3ffe, XPD
|
| 157 | 0x7b15,0xcc48,0xc367,0x85aa,0x3ffe, XPD
|
| 158 | 0xa1d7,0xac2b,0x8698,0x82cd,0x3ffe, XPD
|
| 159 | 0x0000,0x0000,0x0000,0x8000,0x3ffe, XPD
|
| 160 | };
|
| 161 | static const unsigned short B[] = {
|
| 162 | 0x0000,0x0000,0x0000,0x0000,0x0000, XPD
|
| 163 | 0x1f87,0xdb30,0x18f5,0xf73a,0x3fbd, XPD
|
| 164 | 0xac15,0x3e46,0x2932,0xbf4a,0xbfbc, XPD
|
| 165 | 0x7944,0xba66,0xa091,0xcb12,0x3fb9, XPD
|
| 166 | 0xff78,0x40b4,0x2ee6,0xe69a,0x3fbc, XPD
|
| 167 | 0xc895,0x5069,0xe383,0xee53,0xbfbb, XPD
|
| 168 | 0x7cde,0x9376,0x4325,0xf8ab,0x3fbc, XPD
|
| 169 | 0xa10c,0x25e0,0xc093,0xaefd,0xbfbd, XPD
|
| 170 | 0x7d3e,0xea95,0x1366,0xb2fb,0x3fbd, XPD
|
| 171 | 0x5d89,0xeb34,0x5191,0x9301,0x3fbd, XPD
|
| 172 | 0x80d9,0xb883,0xfb10,0xe5eb,0x3fbb, XPD
|
| 173 | 0x045d,0x288c,0xc1ec,0xbedd,0xbfbd, XPD
|
| 174 | 0xeded,0x5c85,0x4630,0x8d5a,0x3fbd, XPD
|
| 175 | 0x9d82,0xe5ac,0x8e0a,0xfd6d,0x3fba, XPD
|
| 176 | 0x6dfd,0xeb58,0xaf14,0x8373,0xbfb9, XPD
|
| 177 | 0xf938,0x7aac,0x91cf,0xe8da,0xbfbc, XPD
|
| 178 | 0x0000,0x0000,0x0000,0x0000,0x0000, XPD
|
| 179 | };
|
| 180 | static const unsigned short R[] = {
|
| 181 | 0xa69b,0x530e,0xee1d,0xfd2a,0x3fee, XPD
|
| 182 | 0xc746,0x8e7e,0x5960,0xa182,0x3ff2, XPD
|
| 183 | 0x63b6,0xadda,0xfd6a,0xaec3,0x3ff5, XPD
|
| 184 | 0xc104,0xfd99,0x5b7c,0x9d95,0x3ff8, XPD
|
| 185 | 0xe05e,0x249d,0x46b8,0xe358,0x3ffa, XPD
|
| 186 | 0x5d1d,0x162c,0xeffc,0xf5fd,0x3ffc, XPD
|
| 187 | 0x79aa,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
|
| 199 | static const
|
| 200 | union
|
| 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
|
| 213 | static long P[] = {
|
| 214 | 0x3ff40000,0xda6ac6f4,0xa8b7b804,
|
| 215 | 0x3ffd0000,0xfae158c0,0xcf027de9,
|
| 216 | 0x3fff0000,0xe00067c9,0x3722405a,
|
| 217 | 0x3fff0000,0xb33387ca,0x6b43cd99,
|
| 218 | };
|
| 219 | static long Q[] = {
|
| 220 | /* 0x3fff0000,0x80000000,0x00000000, */
|
| 221 | 0x40010000,0xa8003b33,0xa4696307,
|
| 222 | 0x40020000,0x8666a51c,0x62d7fec2,
|
| 223 | 0x40010000,0x8666a5d7,0xd072da32,
|
| 224 | };
|
| 225 | static long A[] = {
|
| 226 | 0x3fff0000,0x80000000,0x00000000,
|
| 227 | 0x3ffe0000,0xfa83b2db,0x722a033a,
|
| 228 | 0x3ffe0000,0xf5257d15,0x2486cc2c,
|
| 229 | 0x3ffe0000,0xefe4b99b,0xdcdaf5cb,
|
| 230 | 0x3ffe0000,0xeac0c6e7,0xdd24392f,
|
| 231 | 0x3ffe0000,0xe5b906e7,0x7c8348a8,
|
| 232 | 0x3ffe0000,0xe0ccdeec,0x2a94e111,
|
| 233 | 0x3ffe0000,0xdbfbb797,0xdaf23755,
|
| 234 | 0x3ffe0000,0xd744fcca,0xd69d6af4,
|
| 235 | 0x3ffe0000,0xd2a81d91,0xf12ae45a,
|
| 236 | 0x3ffe0000,0xce248c15,0x1f8480e4,
|
| 237 | 0x3ffe0000,0xc9b9bd86,0x6e2f27a3,
|
| 238 | 0x3ffe0000,0xc5672a11,0x5506dadd,
|
| 239 | 0x3ffe0000,0xc12c4cca,0x66709456,
|
| 240 | 0x3ffe0000,0xbd08a39f,0x580c36bf,
|
| 241 | 0x3ffe0000,0xb8fbaf47,0x62fb9ee9,
|
| 242 | 0x3ffe0000,0xb504f333,0xf9de6484,
|
| 243 | 0x3ffe0000,0xb123f581,0xd2ac2590,
|
| 244 | 0x3ffe0000,0xad583eea,0x42a14ac6,
|
| 245 | 0x3ffe0000,0xa9a15ab4,0xea7c0ef8,
|
| 246 | 0x3ffe0000,0xa5fed6a9,0xb15138ea,
|
| 247 | 0x3ffe0000,0xa2704303,0x0c496819,
|
| 248 | 0x3ffe0000,0x9ef53260,0x91a111ae,
|
| 249 | 0x3ffe0000,0x9b8d39b9,0xd54e5539,
|
| 250 | 0x3ffe0000,0x9837f051,0x8db8a96f,
|
| 251 | 0x3ffe0000,0x94f4efa8,0xfef70961,
|
| 252 | 0x3ffe0000,0x91c3d373,0xab11c336,
|
| 253 | 0x3ffe0000,0x8ea4398b,0x45cd53c0,
|
| 254 | 0x3ffe0000,0x8b95c1e3,0xea8bd6e7,
|
| 255 | 0x3ffe0000,0x88980e80,0x92da8527,
|
| 256 | 0x3ffe0000,0x85aac367,0xcc487b15,
|
| 257 | 0x3ffe0000,0x82cd8698,0xac2ba1d7,
|
| 258 | 0x3ffe0000,0x80000000,0x00000000,
|
| 259 | };
|
| 260 | static long B[51] = {
|
| 261 | 0x00000000,0x00000000,0x00000000,
|
| 262 | 0x3fbd0000,0xf73a18f5,0xdb301f87,
|
| 263 | 0xbfbc0000,0xbf4a2932,0x3e46ac15,
|
| 264 | 0x3fb90000,0xcb12a091,0xba667944,
|
| 265 | 0x3fbc0000,0xe69a2ee6,0x40b4ff78,
|
| 266 | 0xbfbb0000,0xee53e383,0x5069c895,
|
| 267 | 0x3fbc0000,0xf8ab4325,0x93767cde,
|
| 268 | 0xbfbd0000,0xaefdc093,0x25e0a10c,
|
| 269 | 0x3fbd0000,0xb2fb1366,0xea957d3e,
|
| 270 | 0x3fbd0000,0x93015191,0xeb345d89,
|
| 271 | 0x3fbb0000,0xe5ebfb10,0xb88380d9,
|
| 272 | 0xbfbd0000,0xbeddc1ec,0x288c045d,
|
| 273 | 0x3fbd0000,0x8d5a4630,0x5c85eded,
|
| 274 | 0x3fba0000,0xfd6d8e0a,0xe5ac9d82,
|
| 275 | 0xbfb90000,0x8373af14,0xeb586dfd,
|
| 276 | 0xbfbc0000,0xe8da91cf,0x7aacf938,
|
| 277 | 0x00000000,0x00000000,0x00000000,
|
| 278 | };
|
| 279 | static long R[] = {
|
| 280 | 0x3fee0000,0xfd2aee1d,0x530ea69b,
|
| 281 | 0x3ff20000,0xa1825960,0x8e7ec746,
|
| 282 | 0x3ff50000,0xaec3fd6a,0xadda63b6,
|
| 283 | 0x3ff80000,0x9d955b7c,0xfd99c104,
|
| 284 | 0x3ffa0000,0xe35846b8,0x249de05e,
|
| 285 | 0x3ffc0000,0xf5fdeffc,0x162c5d1d,
|
| 286 | 0x3ffe0000,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
|
| 297 | static 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 |
|
| 312 | static VOLATILE long double z;
|
| 313 | static long double w, W, Wa, Wb, ya, yb, u;
|
| 314 |
|
| 315 | static __inline__ long double reducl( long double );
|
| 316 | extern long double __powil ( long double, int );
|
| 317 | extern long double powl ( long double x, long double y);
|
| 318 |
|
| 319 | /* No error checking. We handle Infs and zeros ourselves. */
|
| 320 | static __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 |
|
| 332 | long double powl( x, y )
|
| 333 | long double x, y;
|
| 334 | {
|
| 335 | /* double F, Fa, Fb, G, Ga, Gb, H, Ha, Hb */
|
| 336 | int i, nflg, iyflg, yoddint;
|
| 337 | long e;
|
| 338 |
|
| 339 | if( y == 0.0L )
|
| 340 | return( 1.0L );
|
| 341 |
|
| 342 | #ifdef NANS
|
| 343 | if( isnanl(x) )
|
| 344 | {
|
| 345 | _SET_ERRNO (EDOM);
|
| 346 | return( x );
|
| 347 | }
|
| 348 | if( isnanl(y) )
|
| 349 | {
|
| 350 | _SET_ERRNO (EDOM);
|
| 351 | return( y );
|
| 352 | }
|
| 353 | #endif
|
| 354 |
|
| 355 | if( y == 1.0L )
|
| 356 | return( x );
|
| 357 |
|
| 358 | if( isinfl(y) && (x == -1.0L || x == 1.0L) )
|
| 359 | return( y );
|
| 360 |
|
| 361 | if( x == 1.0L )
|
| 362 | return( 1.0L );
|
| 363 |
|
| 364 | if( 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 | }
|
| 386 | if( 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 | }
|
| 408 | if( 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 |
|
| 420 | w = floorl(y);
|
| 421 | /* Set iyflg to 1 if y is an integer. */
|
| 422 | iyflg = 0;
|
| 423 | if( w == y )
|
| 424 | iyflg = 1;
|
| 425 |
|
| 426 | /* Test for odd integer y. */
|
| 427 | yoddint = 0;
|
| 428 | if( 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 |
|
| 437 | if( 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 |
|
| 462 | nflg = 0; /* flag = 1 if x<0 raised to integer power */
|
| 463 | if( 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 |
|
| 510 | if( 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 |
|
| 522 | if( nflg )
|
| 523 | x = fabsl(x);
|
| 524 |
|
| 525 | /* separate significand from exponent */
|
| 526 | x = frexpl( x, &i );
|
| 527 | e = i;
|
| 528 |
|
| 529 | /* find significand in antilog table A[] */
|
| 530 | i = 1;
|
| 531 | if( x <= douba(17) )
|
| 532 | i = 17;
|
| 533 | if( x <= douba(i+8) )
|
| 534 | i += 8;
|
| 535 | if( x <= douba(i+4) )
|
| 536 | i += 4;
|
| 537 | if( x <= douba(i+2) )
|
| 538 | i += 2;
|
| 539 | if( x >= douba(1) )
|
| 540 | i = -1;
|
| 541 | i += 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 | */
|
| 551 | x -= douba(i);
|
| 552 | x -= doubb(i/2);
|
| 553 | x /= 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 | */
|
| 560 | z = x*x;
|
| 561 | w = x * ( z * polevll( x, P, 3 ) / p1evll( x, Q, 3 ) );
|
| 562 | w = w - ldexpl( z, -1 ); /* w - 0.5 * z */
|
| 563 |
|
| 564 | /* Convert to base 2 logarithm:
|
| 565 | * multiply by log2(e) = 1 + LOG2EA
|
| 566 | */
|
| 567 | z = LOG2EA * w;
|
| 568 | z += w;
|
| 569 | z += LOG2EA * x;
|
| 570 | z += x;
|
| 571 |
|
| 572 | /* Compute exponent term of the base 2 logarithm. */
|
| 573 | w = -i;
|
| 574 | w = ldexpl( w, -LNXT ); /* divide by NXT */
|
| 575 | w += 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 | */
|
| 583 | ya = reducl(y);
|
| 584 | yb = y - ya;
|
| 585 |
|
| 586 | /* (w+z)(ya+yb)
|
| 587 | * = w*ya + w*yb + z*y
|
| 588 | */
|
| 589 | F = z * y + w * yb;
|
| 590 | Fa = reducl(F);
|
| 591 | Fb = F - Fa;
|
| 592 |
|
| 593 | G = Fa + w * ya;
|
| 594 | Ga = reducl(G);
|
| 595 | Gb = G - Ga;
|
| 596 |
|
| 597 | H = Fb + Gb;
|
| 598 | Ha = reducl(H);
|
| 599 | w = ldexpl( Ga + Ha, LNXT );
|
| 600 |
|
| 601 | /* Test the power of 2 for overflow */
|
| 602 | if( w > MEXP )
|
| 603 | {
|
| 604 | _SET_ERRNO (ERANGE);
|
| 605 | mtherr( fname, OVERFLOW );
|
| 606 | return( MAXNUML );
|
| 607 | }
|
| 608 |
|
| 609 | if( w < MNEXP )
|
| 610 | {
|
| 611 | _SET_ERRNO (ERANGE);
|
| 612 | mtherr( fname, UNDERFLOW );
|
| 613 | return( 0.0L );
|
| 614 | }
|
| 615 |
|
| 616 | e = w;
|
| 617 | Hb = H - Ha;
|
| 618 |
|
| 619 | if( 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 | */
|
| 630 | z = 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 | */
|
| 635 | if( e < 0 )
|
| 636 | i = 0;
|
| 637 | else
|
| 638 | i = 1;
|
| 639 | i = e/NXT + i;
|
| 640 | e = NXT*i - e;
|
| 641 | w = douba( e );
|
| 642 | z = w * z; /* 2**-e * ( 1 + (2**Hb-1) ) */
|
| 643 | z = z + w;
|
| 644 | z = ldexpl( z, i ); /* multiply by integer power of 2 */
|
| 645 |
|
| 646 | if( 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 |
|
| 659 | return( z );
|
| 660 | }
|
| 661 |
|
| 662 | static __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. */
|
| 673 | static __inline__ long double reducl(x)
|
| 674 | long double x;
|
| 675 | {
|
| 676 | long 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. */
|
| 683 | t = __convert_inf_to_maxnum (ldexpl( x, LNXT ));
|
| 684 | t = floorl( t );
|
| 685 | t = ldexpl( t, -LNXT );
|
| 686 | return(t);
|
| 687 | }
|