67 lines
1.2 KiB
C
67 lines
1.2 KiB
C
|
/* void _SubUnsArr(src1,src2,n)
|
||
|
*
|
||
|
* ARGUMENT
|
||
|
* unsigned *src1, *src2;
|
||
|
* int n;
|
||
|
*
|
||
|
* DESCRIPTION
|
||
|
* Subtracts src2 from src1 putting the result in src1. It's assumed
|
||
|
* that caller has checked to assure that src1>src2 so no borrow can ever
|
||
|
* be generate (that's why this is a void!!).
|
||
|
*
|
||
|
* SIDE EFFECTS
|
||
|
* The original value of src1 is destroyed.
|
||
|
*
|
||
|
* RETURNS
|
||
|
* None.
|
||
|
*
|
||
|
* AUTHOR
|
||
|
* Brugnoli Giugno 1992
|
||
|
*
|
||
|
* MODIFICATIONS
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <math.h>
|
||
|
#include "gm.h"
|
||
|
#include "gmsystem.h"
|
||
|
|
||
|
extern double pow(double, double);
|
||
|
|
||
|
void _SubUnsArr(src1, src2, n)
|
||
|
unsigned SHORT src1[], src2[];
|
||
|
int n;
|
||
|
{
|
||
|
int i;
|
||
|
unsigned long psrc,maxunsint;
|
||
|
unsigned SHORT carry;
|
||
|
|
||
|
carry=0;
|
||
|
#ifdef SH_LIB
|
||
|
maxunsint=1;
|
||
|
for (i=1;i<=BITSPERUI;i++) maxunsint*=2;
|
||
|
maxunsint--;
|
||
|
#else
|
||
|
maxunsint=(unsigned long)pow(2.,(float)BITSPERUI)-1;
|
||
|
#endif
|
||
|
|
||
|
if (n>0)
|
||
|
{
|
||
|
for (i=0;i<n;i++)
|
||
|
{
|
||
|
if (src2[i]>src1[i])
|
||
|
{
|
||
|
psrc=maxunsint+0x1L+(long)src1[i]-(long)carry;
|
||
|
carry=1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
psrc=src1[i]-carry;
|
||
|
carry=0;
|
||
|
}
|
||
|
src1[i]=(unsigned SHORT)(psrc-(unsigned long)src2[i]);
|
||
|
}
|
||
|
}
|
||
|
}
|