** Expand the Decimal so that it has a least nDigit digits and nFrac ** digits to the right of the decimal point. */
| 4818 | ** digits to the right of the decimal point. |
| 4819 | */ |
| 4820 | static void decimal_expand(Decimal *p, int nDigit, int nFrac){ |
| 4821 | int nAddSig; |
| 4822 | int nAddFrac; |
| 4823 | if( p==0 ) return; |
| 4824 | nAddFrac = nFrac - p->nFrac; |
| 4825 | nAddSig = (nDigit - p->nDigit) - nAddFrac; |
| 4826 | if( nAddFrac==0 && nAddSig==0 ) return; |
| 4827 | p->a = sqlite3_realloc64(p->a, nDigit+1); |
| 4828 | if( p->a==0 ){ |
| 4829 | p->oom = 1; |
| 4830 | return; |
| 4831 | } |
| 4832 | if( nAddSig ){ |
| 4833 | memmove(p->a+nAddSig, p->a, p->nDigit); |
| 4834 | memset(p->a, 0, nAddSig); |
| 4835 | p->nDigit += nAddSig; |
| 4836 | } |
| 4837 | if( nAddFrac ){ |
| 4838 | memset(p->a+p->nDigit, 0, nAddFrac); |
| 4839 | p->nDigit += nAddFrac; |
| 4840 | p->nFrac += nAddFrac; |
| 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | /* |
| 4845 | ** Add the value pB into pA. |