Lines Matching refs:dec

104 static inline void _mpd_check_exp(mpd_t *dec, const mpd_context_t *ctx,
202 mpd_adjexp(const mpd_t *dec)
204 return (dec->exp + dec->digits) - 1;
223 mpd_msword(const mpd_t *dec)
225 assert(dec->len > 0);
226 return dec->data[dec->len-1];
266 mpd_iscanonical(const mpd_t *dec)
268 (void)dec;
274 mpd_isfinite(const mpd_t *dec)
276 return !(dec->flags & MPD_SPECIAL);
281 mpd_isinfinite(const mpd_t *dec)
283 return dec->flags & MPD_INF;
288 mpd_isnan(const mpd_t *dec)
290 return dec->flags & (MPD_NAN|MPD_SNAN);
295 mpd_isnegative(const mpd_t *dec)
297 return dec->flags & MPD_NEG;
302 mpd_ispositive(const mpd_t *dec)
304 return !(dec->flags & MPD_NEG);
309 mpd_isqnan(const mpd_t *dec)
311 return dec->flags & MPD_NAN;
316 mpd_issigned(const mpd_t *dec)
318 return dec->flags & MPD_NEG;
323 mpd_issnan(const mpd_t *dec)
325 return dec->flags & MPD_SNAN;
330 mpd_isspecial(const mpd_t *dec)
332 return dec->flags & MPD_SPECIAL;
337 mpd_iszero(const mpd_t *dec)
339 return !mpd_isspecial(dec) && mpd_msword(dec) == 0;
344 mpd_iszerocoeff(const mpd_t *dec)
346 return mpd_msword(dec) == 0;
351 mpd_isnormal(const mpd_t *dec, const mpd_context_t *ctx)
353 if (mpd_isspecial(dec)) return 0;
354 if (mpd_iszerocoeff(dec)) return 0;
356 return mpd_adjexp(dec) >= ctx->emin;
361 mpd_issubnormal(const mpd_t *dec, const mpd_context_t *ctx)
363 if (mpd_isspecial(dec)) return 0;
364 if (mpd_iszerocoeff(dec)) return 0;
366 return mpd_adjexp(dec) < ctx->emin;
378 mpd_isoddcoeff(const mpd_t *dec)
380 return mpd_isoddword(dec->data[0]);
383 /* 0 if dec is positive, 1 if dec is negative */
385 mpd_sign(const mpd_t *dec)
387 return dec->flags & MPD_NEG;
390 /* 1 if dec is positive, -1 if dec is negative */
392 mpd_arith_sign(const mpd_t *dec)
394 return 1 - 2 * mpd_isnegative(dec);
406 mpd_isdynamic(const mpd_t *dec)
408 return !(dec->flags & MPD_STATIC);
413 mpd_isstatic(const mpd_t *dec)
415 return dec->flags & MPD_STATIC;
420 mpd_isdynamic_data(const mpd_t *dec)
422 return !(dec->flags & MPD_DATAFLAGS);
427 mpd_isstatic_data(const mpd_t *dec)
429 return dec->flags & MPD_STATIC_DATA;
434 mpd_isshared_data(const mpd_t *dec)
436 return dec->flags & MPD_SHARED_DATA;
441 mpd_isconst_data(const mpd_t *dec)
443 return dec->flags & MPD_CONST_DATA;
464 mpd_del(mpd_t *dec)
466 if (mpd_isdynamic_data(dec)) {
467 mpd_free(dec->data);
469 if (mpd_isdynamic(dec)) {
470 mpd_free(dec);
770 _mpd_negate(mpd_t *dec)
772 dec->flags ^= MPD_NEG;
886 _mpd_get_msdigits(mpd_uint_t *hi, mpd_uint_t *lo, const mpd_t *dec,
893 _mpd_div_word(&tmp, &r, dec->digits, MPD_RDIGITS);
897 *lo = dec->data[dec->len-1];
901 else if (dec->len > 1) {
904 tmp = dec->data[dec->len-2] / mpd_pow10[MPD_RDIGITS-(n-r)];
928 mpd_trail_zeros(const mpd_t *dec)
933 for (i=0; i < dec->len; ++i) {
934 if (dec->data[i] != 0) {
935 word = dec->data[i];
950 _mpd_isint(const mpd_t *dec)
954 if (mpd_iszerocoeff(dec)) {
958 tz = mpd_trail_zeros(dec);
959 return (dec->exp + tz >= 0);
964 mpd_isinteger(const mpd_t *dec)
966 if (mpd_isspecial(dec)) {
969 return _mpd_isint(dec);
988 mpd_coeff_ispow10(const mpd_t *dec)
990 if (mpd_word_ispow10(mpd_msword(dec))) {
991 if (_mpd_isallzero(dec->data, dec->len-1)) {
1015 mpd_coeff_isallnine(const mpd_t *dec)
1017 if (mpd_word_isallnine(mpd_msword(dec))) {
1018 if (_mpd_isallnine(dec->data, dec->len-1)) {
1028 mpd_isodd(const mpd_t *dec)
1031 assert(mpd_isinteger(dec));
1032 if (mpd_iszerocoeff(dec)) return 0;
1033 if (dec->exp < 0) {
1034 _mpd_div_word(&q, &r, -dec->exp, MPD_RDIGITS);
1035 q = dec->data[q] / mpd_pow10[r];
1038 return dec->exp == 0 && mpd_isoddword(dec->data[0]);
1043 mpd_iseven(const mpd_t *dec)
1045 return !mpd_isodd(dec);
1701 _mpd_rnd_incr(const mpd_t *dec, mpd_uint_t rnd, const mpd_context_t *ctx)
1711 return (rnd > 5) || ((rnd == 5) && mpd_isoddcoeff(dec));
1713 return !(rnd == 0 || mpd_isnegative(dec));
1715 return !(rnd == 0 || mpd_ispositive(dec));
1721 ld = (int)mpd_lsd(dec->data[0]);
1736 _mpd_apply_round(mpd_t *dec, mpd_uint_t rnd, const mpd_context_t *ctx,
1739 if (_mpd_rnd_incr(dec, rnd, ctx)) {
1749 mpd_uint_t carry = _mpd_baseincr(dec->data, dec->len);
1751 dec->data[dec->len-1] = mpd_pow10[MPD_RDIGITS-1];
1752 dec->exp += 1;
1753 _mpd_check_exp(dec, ctx, status);
1756 mpd_setdigits(dec);
1757 if (dec->digits > ctx->prec) {
1758 mpd_qshiftr_inplace(dec, 1);
1759 dec->exp += 1;
1760 dec->digits = ctx->prec;
1761 _mpd_check_exp(dec, ctx, status);
1770 _mpd_apply_round_excess(mpd_t *dec, mpd_uint_t rnd, const mpd_context_t *ctx,
1773 if (_mpd_rnd_incr(dec, rnd, ctx)) {
1774 mpd_uint_t carry = _mpd_baseincr(dec->data, dec->len);
1776 if (!mpd_qresize(dec, dec->len+1, status)) {
1779 dec->data[dec->len] = 1;
1780 dec->len += 1;
1782 mpd_setdigits(dec);
1792 _mpd_apply_round_fit(mpd_t *dec, mpd_uint_t rnd, const mpd_context_t *ctx,
1795 if (_mpd_rnd_incr(dec, rnd, ctx)) {
1796 mpd_uint_t carry = _mpd_baseincr(dec->data, dec->len);
1798 if (!mpd_qresize(dec, dec->len+1, status)) {
1801 dec->data[dec->len] = 1;
1802 dec->len += 1;
1804 mpd_setdigits(dec);
1805 if (dec->digits > ctx->prec) {
1806 mpd_seterror(dec, MPD_Invalid_operation, status);
1817 _mpd_check_exp(mpd_t *dec, const mpd_context_t *ctx, uint32_t *status)
1822 adjexp = mpd_adjexp(dec);
1825 if (mpd_iszerocoeff(dec)) {
1826 dec->exp = ctx->emax;
1828 dec->exp -= (ctx->prec-1);
1830 mpd_zerocoeff(dec);
1839 mpd_setspecial(dec, mpd_sign(dec), MPD_INF);
1842 mpd_qmaxcoeff(dec, ctx, status);
1843 dec->exp = ctx->emax - ctx->prec + 1;
1846 if (mpd_isnegative(dec)) {
1847 mpd_qmaxcoeff(dec, ctx, status);
1848 dec->exp = ctx->emax - ctx->prec + 1;
1851 mpd_setspecial(dec, MPD_POS, MPD_INF);
1855 if (mpd_ispositive(dec)) {
1856 mpd_qmaxcoeff(dec, ctx, status);
1857 dec->exp = ctx->emax - ctx->prec + 1;
1860 mpd_setspecial(dec, MPD_NEG, MPD_INF);
1870 else if (ctx->clamp && dec->exp > mpd_etop(ctx)) {
1874 shift = dec->exp - mpd_etop(ctx);
1875 if (!mpd_qshiftl(dec, dec, shift, status)) {
1878 dec->exp -= shift;
1880 if (!mpd_iszerocoeff(dec) && adjexp < ctx->emin) {
1890 if (mpd_iszerocoeff(dec)) {
1891 if (dec->exp < etiny) {
1892 dec->exp = etiny;
1893 mpd_zerocoeff(dec);
1900 if (dec->exp < etiny) {
1904 shift = etiny - dec->exp;
1905 rnd = (int)mpd_qshiftr_inplace(dec, shift);
1906 dec->exp = etiny;
1908 _mpd_apply_round_excess(dec, rnd, ctx, status);
1912 if (mpd_iszerocoeff(dec)) {
1913 mpd_zerocoeff(dec);
1930 mpd_check_underflow(mpd_t *dec, const mpd_context_t *ctx, uint32_t *status)
1932 if (mpd_adjexp(dec) < ctx->emin && !mpd_iszero(dec) &&
1933 dec->exp < mpd_etiny(ctx)) {
1940 _mpd_check_round(mpd_t *dec, const mpd_context_t *ctx, uint32_t *status)
1946 if (mpd_isspecial(dec)) {
1950 if (dec->digits > ctx->prec) {
1951 shift = dec->digits - ctx->prec;
1952 rnd = mpd_qshiftr_inplace(dec, shift);
1953 dec->exp += shift;
1954 _mpd_apply_round(dec, rnd, ctx, status);