campo-sirio/gfm/agmn.c
alex ba237a9d91 Patch level : no patch
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Aggiunti i sorgenti per Greenleaf Math Library (gfm.dll)


git-svn-id: svn://10.65.10.50/trunk@10079 c028cbd2-c16b-5b4b-a496-9718f37d4682
2002-02-26 12:19:02 +00:00

73 lines
1.3 KiB
C
Executable File

/* 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"
extern double pow(double, double);
int _AddUnsArrToUnsArr(src1, src2, dst, n)
unsigned SHORT src1[], src2[], dst[];
int n;
{
int i;
unsigned long pdst,maxunsint;
unsigned carry;
carry=0;
#ifdef SH_LIB
maxunsint=1;
for (i=1;i<=BITSPERUI;i++) maxunsint*=2;
maxunsint--;
#else
maxunsint=(unsigned long)pow(2.,(double)BITSPERUI)-1;
#endif
if (n>0)
{
for (i=0;i<n;i++)
{
pdst=carry+(unsigned long)src1[i];
pdst+=(unsigned long)src2[i];
if (pdst>maxunsint)
{
carry=(unsigned)(pdst >> BITSPERUI );
dst[i]=(unsigned SHORT )(pdst & maxunsint );
}
else
{
carry=0;
dst[i]=(unsigned SHORT)pdst;
}
}
if (dst[n-1]>>(BITSPERUI-1))
return(GM_FAILURE);
}
return(GM_SUCCESS);
}