Table Of Contents

Previous topic

Assignment, Conversions, I/O

Next topic

Arithmetic Functions

Attributes of a Decimal

Getting Attributes

mpd_ssize_t mpd_adjexp(const mpd_t *dec);

Adjusted exponent of a decimal: exp + digits - 1

const char *mpd_class(const mpd_t *dec, const mpd_context_t *ctx);

Return a pointer to the class of dec, which is one of sNaN, NaN, -Infinity, -Normal, -Subnormal, -Zero, +Zero, +Subnormal, +Normal, +Infinity.

int mpd_isfinite(const mpd_t *dec);
int mpd_isinfinite(const mpd_t *dec);
int mpd_isnan(const mpd_t *dec);
int mpd_isnegative(const mpd_t *dec);
int mpd_ispositive(const mpd_t *dec);
int mpd_isqnan(const mpd_t *dec);
int mpd_issigned(const mpd_t *dec);
int mpd_issnan(const mpd_t *dec);
int mpd_isspecial(const mpd_t *dec);
int mpd_iszero(const mpd_t *dec);

These functions should be self-explanatory. mpd_issigned is the same as mpd_isnegative.

int mpd_isnormal(const mpd_t *dec, const mpd_context_t *ctx);

Return 0 if the decimal is special or zero, or the exponent is less than emin. Return 1 otherwise.

int mpd_issubnormal(const mpd_t *dec, const mpd_context_t *ctx);

Return 0 if the decimal is special or zero, or the exponent is greater or equal to emin. Return 1 otherwise.

int mpd_isinteger(const mpd_t *dec);

Determine whether dec is an (arbitrary precision) integer. The exponent of an integer is not necessarily zero and may be negative if the coefficient has trailing zeros.

int mpd_isodd(const mpd_t *dec);
int mpd_iseven(const mpd_t *dec);

Determine whether an integer is odd or even. These functions are undefined for non-integers, so they should only be used after calling mpd_isinteger.

uint8_t mpd_sign(const mpd_t *dec);

Return the sign flag, which is 0 for positive decimals and 1 for negative.

int mpd_arith_sign(const mpd_t *dec);

Return 1 for positive decimals and -1 for negative.

mpd_ssize_t mpd_trail_zeros(const mpd_t *dec);

Return the number of trailing zeros in the coefficient.

int mpd_iszerocoeff(const mpd_t *dec);

Test if the coefficient is zero. Only useful for non-special numbers.

int mpd_isoddcoeff(const mpd_t *dec);

Test if the coefficient is odd. Only useful for non-special numbers.

mpd_uint_t mpd_msword(const mpd_t *dec);

Return the most significant word of the coefficient.

int mpd_word_digits(mpd_uint_t word);

Return the number of decimal digits in a word.

mpd_uint_t mpd_msd(mpd_uint_t word);

Return the most significant digit of a word.

mpd_uint_t mpd_lsd(mpd_uint_t word);

Return the least significant digit of a word.

int mpd_isoddword(mpd_uint_t word);

Test if a word is odd.

int mpd_exp_digits(mpd_ssize_t exp);

Number of decimal digits in the exponent.

int mpd_isdynamic(const mpd_t *dec);
int mpd_isstatic(const mpd_t *dec);
int mpd_isdynamic_data(const mpd_t *dec);
int mpd_isstatic_data(const mpd_t *dec);
int mpd_isshared_data(const mpd_t *dec);
int mpd_isconst_data(const mpd_t *dec);

These functions test the memory attributes of a decimal. They are only of interest if features from the section Advanced Memory Handling are used.

Setting Attributes

The functions in this section are mostly low level functions that users of the library should not need. They are required when operating directly on the data field of a decimal, so that len, digits, sign etc. have to be set.

When setting one of {MPD_NEG, MPD_INF, MPD_NAN, MPD_SNAN}, the memory flags must be left intact. All functions in this section take care of this aspect.

void mpd_clear_flags(mpd_t *result);

Clear the numeric flags, but leave the memory flags intact.

void mpd_set_flags(mpd_t *result, uint8_t flags);

Set numeric flags, but leave the memory flags intact.

void mpd_copy_flags(mpd_t *result, const mpd_t *a);

Copy only the numeric flags from a to result.

mpd_ssize_t mpd_digits_to_size(mpd_ssize_t ndigits);

Return the coefficient size required to store ndigits.

void mpd_setdigits(mpd_t *result);

/* Example */
dec->len = 10;
mpd_setdigits(dec);
mpd_set_negative(dec);

Calculate and set digits field. The len field of result is assumed to be correct.

void mpd_set_sign(mpd_t *result, uint8_t sign);

Set the sign of result to MPD_POS or MPD_NEG.

void mpd_set_negative(mpd_t *result);
void mpd_set_positive(mpd_t *result);

Set the sign of result to negative or positive.

void mpd_signcpy(mpd_t *result, const mpd_t *a);

Set the sign of result to the sign of a.

void mpd_set_dynamic(mpd_t *result);
void mpd_set_static(mpd_t *result);
void mpd_set_dynamic_data(mpd_t *result);
void mpd_set_static_data(mpd_t *result);
void mpd_set_shared_data(mpd_t *result);
void mpd_set_const_data(mpd_t *result);

Set memory flags. These functions are only of interest if features from the section Advanced Memory Handling are used.

/* DEPRECATED */
void mpd_set_infinity(mpd_t *result);
void mpd_set_qnan(mpd_t *result);
void mpd_set_snan(mpd_t *result);

All of these functions are deprecated, since they do not set the len and digits fields of result. It is safer to use mpd_setspecial.