2002-02-26 12:19:02 +00:00
|
|
|
/* int _AddUnsArrToUnsArr(src1,src2,dst,n)
|
|
|
|
*
|
|
|
|
* ARGUMENT
|
|
|
|
* unsigned *src1, *src2, *dst;
|
|
|
|
* unsigned n;
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* Adds src1 to src2 giving dst. src1 and src2 are unchanged.
|
|
|
|
* Src1, src2 and dst point to unsigned arrays.
|
|
|
|
*
|
|
|
|
* SIDE EFFECTS
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* GM_SUCCESS if no overflow, otherwise GM_FAILURE.
|
|
|
|
*
|
|
|
|
* AUTHOR
|
|
|
|
* Brugnoli Giugno 1992
|
|
|
|
*
|
|
|
|
* MODIFICATIONS
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "gm.h"
|
|
|
|
#include "gmsystem.h"
|
|
|
|
|
|
|
|
int _AddUnsArrToUnsArr(src1, src2, dst, n)
|
|
|
|
unsigned SHORT src1[], src2[], dst[];
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
int i;
|
2004-03-09 09:49:17 +00:00
|
|
|
unsigned long pdst;
|
|
|
|
unsigned carry = 0;
|
2002-02-26 12:19:02 +00:00
|
|
|
|
|
|
|
if (n>0)
|
|
|
|
{
|
|
|
|
for (i=0;i<n;i++)
|
|
|
|
{
|
|
|
|
pdst=carry+(unsigned long)src1[i];
|
|
|
|
pdst+=(unsigned long)src2[i];
|
2004-03-09 09:49:17 +00:00
|
|
|
if (pdst>MAXUNSINT)
|
2002-02-26 12:19:02 +00:00
|
|
|
{
|
|
|
|
carry=(unsigned)(pdst >> BITSPERUI );
|
2004-03-09 09:49:17 +00:00
|
|
|
dst[i]=(unsigned SHORT )(pdst & MAXUNSINT );
|
2002-02-26 12:19:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
carry=0;
|
|
|
|
dst[i]=(unsigned SHORT)pdst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dst[n-1]>>(BITSPERUI-1))
|
|
|
|
return(GM_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(GM_SUCCESS);
|
|
|
|
}
|
|
|
|
|