2002-02-26 12:19:02 +00:00
|
|
|
/* int _DoubleUnsArr(a,n)
|
|
|
|
*
|
|
|
|
* ARGUMENT
|
|
|
|
* unsigned *a;
|
|
|
|
* int n;
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* Multiplies a by 2 and stores the result in a.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* SIDE EFFECTS
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS if no overflow, otherwise FAILURE.
|
|
|
|
*
|
|
|
|
* AUTHOR
|
|
|
|
* Brugnoli Giugno 1992
|
|
|
|
*
|
|
|
|
* MODIFICATIONS
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "gm.h"
|
|
|
|
#include "gmsystem.h"
|
|
|
|
|
2004-01-26 08:50:57 +00:00
|
|
|
unsigned _DoubleUnsArr(a,n)
|
2002-02-26 12:19:02 +00:00
|
|
|
unsigned SHORT a[];
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
int i;
|
2004-03-09 09:49:17 +00:00
|
|
|
unsigned long pdst;
|
|
|
|
unsigned SHORT carry = 0;
|
2002-02-26 12:19:02 +00:00
|
|
|
|
|
|
|
if (n>0)
|
2004-03-09 09:49:17 +00:00
|
|
|
{
|
2002-02-26 12:19:02 +00:00
|
|
|
for (i=0;i<n;i++)
|
2004-03-09 09:49:17 +00:00
|
|
|
{
|
2002-02-26 12:19:02 +00:00
|
|
|
pdst=carry+(unsigned long)a[i]*2;
|
2004-03-09 09:49:17 +00:00
|
|
|
if (pdst>MAXUNSINT)
|
|
|
|
{
|
2002-02-26 12:19:02 +00:00
|
|
|
carry=(unsigned SHORT)(pdst>> BITSPERUI );
|
2004-03-09 09:49:17 +00:00
|
|
|
a[i]=(unsigned SHORT)(pdst & MAXUNSINT );
|
|
|
|
}
|
2002-02-26 12:19:02 +00:00
|
|
|
else
|
2004-03-09 09:49:17 +00:00
|
|
|
{
|
2002-02-26 12:19:02 +00:00
|
|
|
a[i]=(unsigned SHORT)pdst;
|
|
|
|
carry=0;
|
2004-03-09 09:49:17 +00:00
|
|
|
}
|
2002-02-26 12:19:02 +00:00
|
|
|
}
|
2004-03-09 09:49:17 +00:00
|
|
|
if ((a[n-1]) >> (BITSPERUI-1))
|
|
|
|
return(FAILURE);
|
|
|
|
}
|
|
|
|
return(GM_SUCCESS);
|
2002-02-26 12:19:02 +00:00
|
|
|
}
|