ba237a9d91
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
133 lines
2.2 KiB
C
Executable File
133 lines
2.2 KiB
C
Executable File
/* int _MulUnsArrP10AndAddInt(pa,c)
|
|
*
|
|
* ARGUMENT
|
|
* unsigned pa[];
|
|
* int c; # to add after mult by 10
|
|
*
|
|
* DESCRIPTION
|
|
* Multiplies the number (<=80bits) in the int array by decimal 10
|
|
* and adds 'c' to it. Used in the divide routines for adjusting,
|
|
*
|
|
* SIDE EFFECTS
|
|
* The value of pa is unchanged on overflow.
|
|
*
|
|
* RETURNS
|
|
* GM_SUCCES if no overflow, otherwise GM_OVERFLOW
|
|
*
|
|
* AUTHOR
|
|
* Brugnoli Giugno 1992
|
|
*
|
|
* MODIFICATIONS
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
#include "gm.h"
|
|
#include "gmsystem.h"
|
|
|
|
extern double pow(double, double);
|
|
|
|
int Mltply(sr,num,m)
|
|
unsigned SHORT sr[],num;
|
|
int m;
|
|
{
|
|
int i;
|
|
unsigned long pdst[10],maxunsint;
|
|
unsigned SHORT carry;
|
|
|
|
#ifdef SH_LIB
|
|
maxunsint=1;
|
|
for (i=1;i<=BITSPERUI;i++) maxunsint*=2;
|
|
maxunsint--;
|
|
#else
|
|
maxunsint=(unsigned long)pow(2.,(float)BITSPERUI)-1;
|
|
#endif
|
|
carry=0;
|
|
|
|
for (i=0;i<m;i++)
|
|
{
|
|
pdst[i]=(unsigned long)sr[i]*num;
|
|
}
|
|
|
|
for (i=0;i<m;i++)
|
|
{
|
|
pdst[i]+=carry;
|
|
if (pdst[i]>maxunsint)
|
|
{
|
|
carry=(unsigned SHORT)(pdst[i]>>BITSPERUI);
|
|
sr[i]=(unsigned SHORT)(pdst[i]&maxunsint);
|
|
}
|
|
else
|
|
{
|
|
carry=0;
|
|
sr[i]=(unsigned SHORT)pdst[i];
|
|
}
|
|
}
|
|
return( ((carry)||(sr[m-1]>>(BITSPERUI-1)))? GM_OVERFLOW : GM_SUCCESS );
|
|
}
|
|
|
|
|
|
int _MulUnsArrP10AndAddInt(pa,c)
|
|
unsigned SHORT pa[];
|
|
int c;
|
|
{
|
|
|
|
int ppdf,k,i;
|
|
unsigned long maxunsint,pdst,carry;
|
|
unsigned SHORT dst[10];
|
|
|
|
k=GM_SUCCESS;
|
|
#ifdef SH_LIB
|
|
maxunsint=1;
|
|
for (i=1;i<=BITSPERUI;i++) maxunsint*=2;
|
|
maxunsint--;
|
|
#else
|
|
maxunsint=(unsigned long)pow(2.,(float)BITSPERUI)-1;
|
|
#endif
|
|
ppdf=10;
|
|
for (i=0;i<=9;i++)
|
|
{
|
|
dst[i]=(i<5?pa[i]:0);
|
|
}
|
|
k=Mltply(dst,ppdf,5);
|
|
i=0;
|
|
carry=c;
|
|
|
|
if (k!=GM_OVERFLOW)
|
|
{
|
|
do
|
|
{
|
|
pdst=(long)dst[i]+(long)carry;
|
|
if (pdst>maxunsint)
|
|
{
|
|
carry=(pdst>>BITSPERUI);
|
|
dst[i]=(unsigned SHORT)(pdst&maxunsint);
|
|
}
|
|
else
|
|
{
|
|
dst[i]=(unsigned SHORT)pdst;
|
|
carry=0;
|
|
}
|
|
i++;
|
|
}
|
|
while (carry);
|
|
}
|
|
|
|
if (i>5)
|
|
{
|
|
k=GM_OVERFLOW;
|
|
}
|
|
|
|
if (!k)
|
|
{
|
|
for (i=0;i<5;i++)
|
|
{
|
|
pa[i]=dst[i];
|
|
}
|
|
}
|
|
|
|
return(k);
|
|
|
|
}
|