MCPcopy Create free account
hub / github.com/audacity/audacity / decimal_add

Function decimal_add

lib-src/sqlite/shell.c:4849–4912  ·  view source on GitHub ↗

** Add the value pB into pA. ** ** Both pA and pB might become denormalized by this routine. */

Source from the content-addressed store, hash-verified

4847** Both pA and pB might become denormalized by this routine.
4848*/
4849static void decimal_add(Decimal *pA, Decimal *pB){
4850 int nSig, nFrac, nDigit;
4851 int i, rc;
4852 if( pA==0 ){
4853 return;
4854 }
4855 if( pA->oom || pB==0 || pB->oom ){
4856 pA->oom = 1;
4857 return;
4858 }
4859 if( pA->isNull || pB->isNull ){
4860 pA->isNull = 1;
4861 return;
4862 }
4863 nSig = pA->nDigit - pA->nFrac;
4864 if( nSig && pA->a[0]==0 ) nSig--;
4865 if( nSig<pB->nDigit-pB->nFrac ){
4866 nSig = pB->nDigit - pB->nFrac;
4867 }
4868 nFrac = pA->nFrac;
4869 if( nFrac<pB->nFrac ) nFrac = pB->nFrac;
4870 nDigit = nSig + nFrac + 1;
4871 decimal_expand(pA, nDigit, nFrac);
4872 decimal_expand(pB, nDigit, nFrac);
4873 if( pA->oom || pB->oom ){
4874 pA->oom = 1;
4875 }else{
4876 if( pA->sign==pB->sign ){
4877 int carry = 0;
4878 for(i=nDigit-1; i>=0; i--){
4879 int x = pA->a[i] + pB->a[i] + carry;
4880 if( x>=10 ){
4881 carry = 1;
4882 pA->a[i] = x - 10;
4883 }else{
4884 carry = 0;
4885 pA->a[i] = x;
4886 }
4887 }
4888 }else{
4889 signed char *aA, *aB;
4890 int borrow = 0;
4891 rc = memcmp(pA->a, pB->a, nDigit);
4892 if( rc<0 ){
4893 aA = pB->a;
4894 aB = pA->a;
4895 pA->sign = !pA->sign;
4896 }else{
4897 aA = pA->a;
4898 aB = pB->a;
4899 }
4900 for(i=nDigit-1; i>=0; i--){
4901 int x = aA[i] - aB[i] - borrow;
4902 if( x<0 ){
4903 pA->a[i] = x+10;
4904 borrow = 1;
4905 }else{
4906 pA->a[i] = x;

Callers 4

decimalAddFuncFunction · 0.85
decimalSubFuncFunction · 0.85
decimalSumStepFunction · 0.85
decimalSumInverseFunction · 0.85

Calls 1

decimal_expandFunction · 0.85

Tested by

no test coverage detected