1428
Returns the size of array to hold a decimal with given precision and scale
1432
(multiply by sizeof(dec1) to get the size if bytes)
1435
int decimal_size(int precision, int scale)
1437
assert(scale >= 0 && precision > 0 && scale <= precision);
1438
return ROUND_UP(precision-scale)+ROUND_UP(scale);
1442
1428
Returns the size of array to hold a binary representation of a decimal
1671
Returns the size of the result of the operation
1674
decimal_result_size()
1675
from1 - operand of the unary operation or first operand of the
1677
from2 - second operand of the binary operation
1678
op - operation. one char '+', '-', '*', '/' are allowed
1679
others may be added later
1680
param - extra param to the operation. unused for '+', '-', '*'
1681
scale increment for '/'
1684
returned valued may be larger than the actual buffer requred
1685
in the operation, as decimal_result_size, by design, operates on
1686
precision/scale values only and not on the actual decimal number
1689
size of to->buf array in dec1 elements. to get size in bytes
1690
multiply by sizeof(dec1)
1693
int decimal_result_size(decimal_t *from1, decimal_t *from2, char op, int param)
1697
return ROUND_UP(max(from1->intg, from2->intg)) +
1698
ROUND_UP(max(from1->frac, from2->frac));
1700
return ROUND_UP(max(from1->intg, from2->intg)+1) +
1701
ROUND_UP(max(from1->frac, from2->frac));
1703
return ROUND_UP(from1->intg+from2->intg)+
1704
ROUND_UP(from1->frac)+ROUND_UP(from2->frac);
1706
return ROUND_UP(from1->intg+from2->intg+1+from1->frac+from2->frac+param);
1709
return -1; /* shut up the warning */
1712
1656
static int do_add(decimal_t *from1, decimal_t *from2, decimal_t *to)
1714
1658
int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),