123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- #include <cdefs-compat.h>
- __FBSDID("$FreeBSD$");
- #include <float.h>
- #ifdef __i386__
- #include <ieeefp.h>
- #endif
- #include "fpmath.h"
- #include "math.h"
- #include "math_private.h"
- #include "k_expl.h"
- static const volatile long double
- huge = 0x1p10000L,
- tiny = 0x1p-10000L;
- static const long double
- twom10000 = 0x1p-10000L;
- static const union IEEEl2bits
- o_thresholdu = LD80C(0xb17217f7d1cf79ab, 13, 11356.5234062941439488L),
- #define o_threshold (o_thresholdu.e)
- u_thresholdu = LD80C(0xb21dfe7f09e2baa9, 13, -11399.4985314888605581L);
- #define u_threshold (u_thresholdu.e)
- long double
- expl(long double x)
- {
- union IEEEl2bits u;
- long double hi, lo, t, twopk;
- int k;
- uint16_t hx, ix;
- DOPRINT_START(&x);
-
- u.e = x;
- hx = u.xbits.expsign;
- ix = hx & 0x7fff;
- if (ix >= BIAS + 13) {
- if (ix == BIAS + LDBL_MAX_EXP) {
- if (hx & 0x8000)
- RETURNP(-1 / x);
- RETURNP(x + x);
- }
- if (x > o_threshold)
- RETURNP(huge * huge);
- if (x < u_threshold)
- RETURNP(tiny * tiny);
- } else if (ix < BIAS - 75) {
- RETURN2P(1, x);
- }
- ENTERI();
- twopk = 1;
- __k_expl(x, &hi, &lo, &k);
- t = SUM2P(hi, lo);
-
- if (k >= LDBL_MIN_EXP) {
- if (k == LDBL_MAX_EXP)
- RETURNI(t * 2 * 0x1p16383L);
- SET_LDBL_EXPSIGN(twopk, BIAS + k);
- RETURNI(t * twopk);
- } else {
- SET_LDBL_EXPSIGN(twopk, BIAS + k + 10000);
- RETURNI(t * twopk * twom10000);
- }
- }
- static const double
- T1 = -0.1659,
- T2 = 0.1659;
- static const union IEEEl2bits
- B3 = LD80C(0xaaaaaaaaaaaaaaab, -3, 1.66666666666666666671e-1L),
- B4 = LD80C(0xaaaaaaaaaaaaaaac, -5, 4.16666666666666666712e-2L);
- static const double
- B5 = 8.3333333333333245e-3,
- B6 = 1.3888888888888861e-3,
- B7 = 1.9841269841532042e-4,
- B8 = 2.4801587302069236e-5,
- B9 = 2.7557316558468562e-6,
- B10 = 2.7557315829785151e-7,
- B11 = 2.5063168199779829e-8,
- B12 = 2.0887164654459567e-9;
- long double
- expm1l(long double x)
- {
- union IEEEl2bits u, v;
- long double fn, hx2_hi, hx2_lo, q, r, r1, r2, t, twomk, twopk, x_hi;
- long double x_lo, x2, z;
- long double x4;
- int k, n, n2;
- uint16_t hx, ix;
- DOPRINT_START(&x);
-
- u.e = x;
- hx = u.xbits.expsign;
- ix = hx & 0x7fff;
- if (ix >= BIAS + 6) {
- if (ix == BIAS + LDBL_MAX_EXP) {
- if (hx & 0x8000)
- RETURNP(-1 / x - 1);
- RETURNP(x + x);
- }
- if (x > o_threshold)
- RETURNP(huge * huge);
-
- if (hx & 0x8000)
- RETURN2P(tiny, -1);
- }
- ENTERI();
- if (T1 < x && x < T2) {
- if (ix < BIAS - 74) {
-
- RETURNPI(x == 0 ? x :
- (0x1p100 * x + fabsl(x)) * 0x1p-100);
- }
- x2 = x * x;
- x4 = x2 * x2;
- q = x4 * (x2 * (x4 *
-
- (x2 * B12 + (x * B11 + B10)) +
- (x2 * (x * B9 + B8) + (x * B7 + B6))) +
- (x * B5 + B4.e)) + x2 * x * B3.e;
- x_hi = (float)x;
- x_lo = x - x_hi;
- hx2_hi = x_hi * x_hi / 2;
- hx2_lo = x_lo * (x + x_hi) / 2;
- if (ix >= BIAS - 7)
- RETURN2PI(hx2_hi + x_hi, hx2_lo + x_lo + q);
- else
- RETURN2PI(x, hx2_lo + q + hx2_hi);
- }
-
-
- fn = x * INV_L + 0x1.8p63 - 0x1.8p63;
- #if defined(HAVE_EFFICIENT_IRINTL)
- n = irintl(fn);
- #elif defined(HAVE_EFFICIENT_IRINT)
- n = irint(fn);
- #else
- n = (int)fn;
- #endif
- n2 = (unsigned)n % INTERVALS;
- k = n >> LOG2_INTERVALS;
- r1 = x - fn * L1;
- r2 = fn * -L2;
- r = r1 + r2;
-
- v.e = 1;
- v.xbits.expsign = BIAS + k;
- twopk = v.e;
-
- z = r * r;
- q = r2 + z * (A2 + r * A3) + z * z * (A4 + r * A5) + z * z * z * A6;
- t = (long double)tbl[n2].lo + tbl[n2].hi;
- if (k == 0) {
- t = SUM2P(tbl[n2].hi - 1, tbl[n2].lo * (r1 + 1) + t * q +
- tbl[n2].hi * r1);
- RETURNI(t);
- }
- if (k == -1) {
- t = SUM2P(tbl[n2].hi - 2, tbl[n2].lo * (r1 + 1) + t * q +
- tbl[n2].hi * r1);
- RETURNI(t / 2);
- }
- if (k < -7) {
- t = SUM2P(tbl[n2].hi, tbl[n2].lo + t * (q + r1));
- RETURNI(t * twopk - 1);
- }
- if (k > 2 * LDBL_MANT_DIG - 1) {
- t = SUM2P(tbl[n2].hi, tbl[n2].lo + t * (q + r1));
- if (k == LDBL_MAX_EXP)
- RETURNI(t * 2 * 0x1p16383L - 1);
- RETURNI(t * twopk - 1);
- }
- v.xbits.expsign = BIAS - k;
- twomk = v.e;
- if (k > LDBL_MANT_DIG - 1)
- t = SUM2P(tbl[n2].hi, tbl[n2].lo - twomk + t * (q + r1));
- else
- t = SUM2P(tbl[n2].hi - twomk, tbl[n2].lo + t * (q + r1));
- RETURNI(t * twopk);
- }
|