Lines Matching refs:exp

82 #define MPD_NEW_STATIC(name, flags, exp, digits, len) \
84 mpd_t name = {flags|MPD_STATIC|MPD_STATIC_DATA, exp, digits, \
87 #define MPD_NEW_CONST(name, flags, exp, digits, len, alloc, initval) \
89 mpd_t name = {flags|MPD_STATIC|MPD_CONST_DATA, exp, digits, \
94 a->exp, a->digits, a->len, a->alloc, a->data}
107 mpd_ssize_t exp);
119 mpd_uint_t exp, uint8_t resultsign,
204 return (dec->exp + dec->digits) - 1;
258 mpd_exp_digits(mpd_ssize_t exp)
260 exp = (exp < 0) ? -exp : exp;
261 return mpd_word_digits(exp);
835 _settriple(result, mpd_sign(result), 0, result->exp);
959 return (dec->exp + tz >= 0);
1033 if (dec->exp < 0) {
1034 _mpd_div_word(&q, &r, -dec->exp, MPD_RDIGITS);
1038 return dec->exp == 0 && mpd_isoddword(dec->data[0]);
1054 _ssettriple(mpd_t *result, uint8_t sign, mpd_uint_t a, mpd_ssize_t exp)
1057 result->exp = exp;
1065 _settriple(mpd_t *result, uint8_t sign, mpd_uint_t a, mpd_ssize_t exp)
1069 result->exp = exp;
1082 result->exp = result->digits = result->len = 0;
1092 result->exp = result->digits = result->len = 0;
1222 result->exp = 0;
1352 if (a->digits+a->exp > MPD_RDIGITS+1) {
1357 if (a->exp < 0) {
1362 /* At this point a->digits+a->exp <= MPD_RDIGITS+1,
1367 mpd_qsshiftr(&tmp, a, -a->exp);
1368 tmp.exp = 0;
1378 if (a->exp > 0) {
1379 _mpd_mul_words(&hi, &lo, lo, mpd_pow10[a->exp]);
1752 dec->exp += 1;
1759 dec->exp += 1;
1826 dec->exp = ctx->emax;
1828 dec->exp -= (ctx->prec-1);
1843 dec->exp = ctx->emax - ctx->prec + 1;
1848 dec->exp = ctx->emax - ctx->prec + 1;
1857 dec->exp = ctx->emax - ctx->prec + 1;
1870 else if (ctx->clamp && dec->exp > mpd_etop(ctx)) {
1871 /* At this point adjexp=exp+digits-1 <= emax and exp > etop=emax-prec+1:
1872 * (1) shift = exp -emax+prec-1 > 0
1873 * (2) digits+shift = exp+digits-1 - emax + prec <= prec */
1874 shift = dec->exp - mpd_etop(ctx);
1878 dec->exp -= shift;
1881 /* Underflow is impossible, since exp < etiny=emin-prec+1
1882 * and exp > etop=emax-prec+1 would imply emax < emin. */
1891 if (dec->exp < etiny) {
1892 dec->exp = etiny;
1900 if (dec->exp < etiny) {
1901 /* At this point adjexp=exp+digits-1 < emin and exp < etiny=emin-prec+1:
1902 * (1) shift = emin-prec+1 - exp > 0
1903 * (2) digits-shift = exp+digits-1 - emin + prec < prec */
1904 shift = etiny - dec->exp;
1906 dec->exp = etiny;
1918 /* Case exp >= etiny=emin-prec+1:
1919 * (1) adjexp=exp+digits-1 < emin
1920 * (2) digits < emin-exp+1 <= prec */
1933 dec->exp < mpd_etiny(ctx)) {
1953 dec->exp += shift;
1987 dest->exp = src->exp;
2009 result->exp = a->exp;
2028 result->exp = a->exp;
2048 result->exp = a->exp;
2067 result->exp = a->exp;
2201 if (a->exp != b->exp) {
2202 /* Cannot wrap: a->exp + a->digits = b->exp + b->digits, so
2203 * a->exp - b->exp = b->digits - a->digits. */
2204 shift = a->exp - b->exp;
2214 * At this point adjexp(a) == adjexp(b) and a->exp == b->exp,
2400 aa.exp = bb.exp = 0;
2418 if (c == 0 && a->exp != b->exp) {
2419 c = (a->exp < b->exp) ? -1 : 1;
2484 c = (a->exp < b->exp) ? -1 : 1;
2521 result->exp = a->exp;
2581 result->exp = a->exp;
2666 result->exp = a->exp;
2688 a->exp != 0 || b->exp != 0) {
2756 result->exp = 0;
2809 if (mpd_isspecial(a) || mpd_isnegative(a) || a->exp != 0) {
2836 result->exp = 0;
2879 a->exp != 0 || b->exp != 0) {
2949 result->exp = 0;
2979 if (b->exp != 0 || mpd_isinfinite(b)) {
3047 int64_t exp;
3051 mpd_ssize_t exp;
3059 if (b->exp != 0 || mpd_isinfinite(b)) {
3078 exp = a->exp + (int64_t)n * mpd_arith_sign(b);
3079 exp = (exp > MPD_EXP_INF) ? MPD_EXP_INF : exp;
3080 exp = (exp < MPD_EXP_CLAMP) ? MPD_EXP_CLAMP : exp;
3082 x = (a->exp < 0) ? -a->exp : a->exp;
3083 x_sign = (a->exp < 0) ? 1 : 0;
3096 exp = x_sign ? -((mpd_ssize_t)x) : (mpd_ssize_t)x;
3100 result->exp = (mpd_ssize_t)exp;
3154 if (b->exp != 0 || mpd_isinfinite(b)) {
3198 a->exp != 0 || b->exp != 0) {
3268 result->exp = 0;
3343 mpd_ssize_t exp, i;
3349 if (big->exp != small->exp) {
3350 if (small->exp > big->exp) {
3356 exp = big->exp - 1;
3357 exp += (big->digits > ctx->prec) ? 0 : big->digits-ctx->prec-1;
3358 if (mpd_adjexp(small) < exp) {
3363 * adjexp(small) < exp if and only if:
3367 * exp = bexp+bdigits-prec-2
3378 * exp = bexp-1
3392 tiny.exp = exp;
3399 shift = big->exp - small->exp;
3407 result->exp = small->exp;
3759 mpd_ssize_t shift, exp, tz;
3785 exp = a->exp - b->exp;
3786 _settriple(q, sign_a^sign_b, 0, exp);
3792 ideal_exp = a->exp - b->exp;
3793 exp = ideal_exp - shift;
3852 shift = ideal_exp - exp;
3863 exp += shift;
3866 q->exp = exp;
3959 ideal_exp = (a->exp > b->exp) ? b->exp : a->exp;
3964 r->exp = ideal_exp;
3971 if (a->exp > b->exp) {
3973 shift = a->exp - b->exp;
3977 r->exp = ideal_exp;
3995 * (1) 0 <= a->exp + a->digits - b->exp - b->digits <= prec
3996 * (2) a->exp - b->exp >= b->digits - a->digits
3997 * (3) a->exp - b->exp <= prec + b->digits - a->digits
3999 if (a->exp != b->exp) {
4000 shift = a->exp - b->exp;
4066 q->exp = 0;
4078 r->exp = ideal_exp;
4285 result->exp -= shift;
4341 * 1) exp-iter-approx-lower-bound: The term below evaluated
4344 * 2) exp-iter-approx-upper-bound: The term below is less than
4416 t = a->digits + a->exp;
4444 result->exp -= t;
4488 /* exp(a) */
4541 ulpexp = result->exp + result->digits - workctx.prec;
4544 ulpexp = result->exp;
4727 result->exp = -(result->digits-1);
4740 i = ln_schedule_prec(klist, prec+2, -result->exp);
4875 a_exp = a->exp;
4881 z->exp = -3;
4888 v.exp = -(a_digits - 1);
4895 v.exp = -a_digits;
4927 tmp.exp += 1;
4935 tmp.exp -= 1;
4958 vtmp.exp += shift;
5093 result->exp + result->digits-workctx.prec);
5242 result->exp + result->digits-workctx.prec);
5983 result->exp = big->exp + small->exp;
6165 result->exp = mpd_etop(ctx);
6212 result->exp = mpd_etop(ctx);
6284 _mpd_qpow_uint(mpd_t *result, const mpd_t *base, mpd_uint_t exp,
6290 if (exp == 0) {
6299 n = mpd_bits[mpd_bsr(exp)];
6302 if (exp & n) {
6361 * abs(result - base**exp) < 0.1 * 10**-prec * abs(base**exp)
6364 _mpd_qpow_int(mpd_t *result, const mpd_t *base, const mpd_t *exp,
6375 workctx.prec += (exp->digits + exp->exp + 2);
6378 if (mpd_isnegative(exp)) {
6395 n = mpd_qabs_uint(exp, &workctx.status);
6397 if (!mpd_qcopy(&texp, exp, status)) {
6433 result->exp = -shift;
6449 _qcheck_pow_one(mpd_t *result, const mpd_t *base, const mpd_t *exp,
6458 if (_mpd_isint(exp)) {
6459 if (mpd_isnegative(exp)) {
6464 mpd_qmul_ssize(result, exp, -base->exp, ctx, &workstatus);
6487 result->exp = -shift;
6644 _mpd_qpow_exact(mpd_t *result, const mpd_t *base, const mpd_t *exp,
6656 _mpd_qpow_real(mpd_t *result, const mpd_t *base, const mpd_t *exp,
6662 if (!mpd_qcopy(&texp, exp, status)) {
6677 * y := log(base) * exp
6706 /* The power function: base**exp */
6708 mpd_qpow(mpd_t *result, const mpd_t *base, const mpd_t *exp,
6715 if (mpd_isspecial(base) || mpd_isspecial(exp)) {
6716 if (mpd_qcheck_nans(result, base, exp, ctx, status)) {
6720 if (mpd_isinteger(exp)) {
6722 resultsign = mpd_isnegative(base) && mpd_isodd(exp);
6726 if (mpd_iszero(exp)) {
6729 else if (mpd_isnegative(exp)) {
6738 if (!intexp || mpd_isinfinite(exp)) {
6743 if (mpd_isinfinite(exp)) {
6750 cmp *= mpd_arith_sign(exp);
6761 if (mpd_iszero(exp)) {
6764 else if (mpd_isnegative(exp)) {
6772 if (mpd_iszero(exp)) {
6776 if (_qcheck_pow_one(result, base, exp, resultsign, ctx, status) == 0) {
6779 if (_qcheck_pow_bounds(result, base, exp, resultsign, ctx, status)) {
6784 _mpd_qpow_int(result, base, exp, resultsign, ctx, status);
6787 _mpd_qpow_real(result, base, exp, ctx, status);
6791 result->exp = -shift;
6806 _mpd_qpowmod_uint(mpd_t *result, mpd_t *base, mpd_uint_t exp,
6816 while (exp > 0) {
6817 if (exp & 1) {
6823 exp >>= 1;
6827 /* The powmod function: (base**exp) % mod */
6829 mpd_qpowmod(mpd_t *result, const mpd_t *base, const mpd_t *exp,
6846 if (mpd_isspecial(base) || mpd_isspecial(exp) || mpd_isspecial(mod)) {
6847 if (mpd_qcheck_3nans(result, base, exp, mod, ctx, status)) {
6855 if (!_mpd_isint(base) || !_mpd_isint(exp) || !_mpd_isint(mod)) {
6863 if (mod->digits+mod->exp > ctx->prec) {
6868 sign = (mpd_isnegative(base)) && (mpd_isodd(exp));
6869 if (mpd_iszerocoeff(exp)) {
6878 if (mpd_isnegative(exp)) {
6899 tbase_exp = tbase.exp;
6900 tbase.exp = 0;
6902 mpd_qround_to_int(&texp, exp, &maxcontext, status);
6903 texp_exp = texp.exp;
6904 texp.exp = 0;
6906 /* base = (base.int % modulo * pow(10, base.exp, modulo)) % modulo */
6965 mpd_ssize_t b_exp = b->exp;
6981 if (b->exp > ctx->emax || b->exp < mpd_etiny(ctx)) {
6987 _settriple(result, mpd_sign(a), 0, b->exp);
6993 expdiff = a->exp - b->exp;
7004 result->exp = b_exp;
7014 result->exp = b_exp;
7063 /* After the finalizing above result->exp <= maxexp. */
7064 maxshift = maxexp - result->exp;
7068 result->exp += shift;
7204 _mpd_qrescale(mpd_t *result, const mpd_t *a, mpd_ssize_t exp,
7216 _settriple(result, mpd_sign(a), 0, exp);
7220 expdiff = a->exp - exp;
7230 result->exp = exp;
7238 result->exp = exp;
7252 * Rescale a number so that it has exponent 'exp'. Does not regard context
7256 * MPD_MIN_ETINY <= exp <= MPD_MAX_EMAX+1
7260 mpd_qrescale(mpd_t *result, const mpd_t *a, mpd_ssize_t exp,
7263 if (exp > MPD_MAX_EMAX+1 || exp < MPD_MIN_ETINY) {
7268 _mpd_qrescale(result, a, exp, ctx, status);
7276 * MPD_MIN_ETINY-MPD_MAX_PREC <= exp <= MPD_MAX_EMAX+1
7280 mpd_qrescale_fmt(mpd_t *result, const mpd_t *a, mpd_ssize_t exp,
7283 if (exp > MPD_MAX_EMAX+1 || exp < MPD_MIN_ETINY-MPD_MAX_PREC) {
7288 _mpd_qrescale(result, a, exp, ctx, status);
7306 if (a->exp >= 0) {
7315 rnd = mpd_qshiftr(result, a, -a->exp, status);
7319 result->exp = 0;
7398 return a->exp == b->exp;
7436 assert(v->exp == -v->digits);
7446 z->exp = -(MPD_RDIGITS-2);
7477 adj = v->digits + v->exp;
7478 v->exp = -v->digits;
7503 t.exp = -varcontext.prec;
7520 z->exp -= adj;
7558 aa.exp = 0;
7559 bb.exp = 0;
7743 z->exp = -6;
7772 ideal_exp = -(a->exp - (a->exp & 1)) / 2;
7783 if ((v->digits+v->exp) & 1) {
7785 v->exp = -fracdigits;
7795 v->exp = -fracdigits;
7803 adj = (a->exp-v->exp) / 2;
7821 t.exp += shift;
7832 z->exp -= adj;
7835 shift = ideal_exp - result->exp;
7839 result->exp += shift;
7902 ideal_exp = (a->exp - (a->exp & 1)) / 2;
7931 c.exp = 0;
7933 if (a->exp & 1) {
8005 result->exp = ideal_exp;
8092 digits = a->digits+a->exp;
8408 if (src->exp >= 0) {
8409 if (!mpd_qshiftl(&tsrc, src, src->exp, status)) {
8414 if (mpd_qshiftr(&tsrc, src, -src->exp, status) == MPD_UINT_MAX) {
8485 if (src->exp >= 0) {
8486 if (!mpd_qshiftl(&tsrc, src, src->exp, status)) {
8491 if (mpd_qshiftr(&tsrc, src, -src->exp, status) == MPD_UINT_MAX) {
8575 result->exp = 0;
8651 result->exp = 0;
8742 _set_uint128_coeff_exp(mpd_t *result, uint64_t hi, uint64_t lo, mpd_ssize_t exp)
8762 result->exp = exp;
8787 mpd_ssize_t exp;
8790 if (triple->exp < MPD_SSIZE_MIN || triple->exp > MPD_SSIZE_MAX) {
8794 exp = (mpd_ssize_t)triple->exp;
8798 if (sign > 1 || exp != 0) {
8809 if (_set_uint128_coeff_exp(result, hi, lo, exp) < 0) {
8817 if (sign > 1 || hi != 0 || lo != 0 || exp != 0) {
8834 if (exp > MPD_EXP_INF) {
8835 exp = MPD_EXP_INF;
8837 if (exp == MPD_SSIZE_MIN) {
8838 exp = MPD_SSIZE_MIN+1;
8841 if (_set_uint128_coeff_exp(result, hi, lo, exp) < 0) {
8983 coeff.exp = 0;
9005 triple.exp = a->exp;