campo-sirio/gfm/mul10.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

105 lines
1.7 KiB
C
Executable File

/* int _MulUnsArrByPwrOf10(pa,n,w)
*
* ARGUMENT
* unsigned pa[];
* int n; power of 10 to multiply by
* int w; number of digits
*
* DESCRIPTION
* Multiplies the pa[] array by 10^n (0<n<47),
*
* 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 Multiply(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)? GM_OVERFLOW : GM_SUCCESS );
}
int _MulUnsArrByPwrOf10(pa,n,w)
unsigned SHORT pa[];
int n,w;
{
int ppdf,k,i;
k=GM_SUCCESS;
if (n>47)
{
k=GM_OVERFLOW;
}
while ((n>4)&&(k==GM_SUCCESS))
{
k=Multiply(pa,10000,w);
n-=4;
}
if (k!=GM_OVERFLOW)
{
#ifdef SH_LIB
ppdf=1;
for (i=1;i<=n;i++) ppdf*=10;
#else
ppdf=(int)pow(10.,(double)n);
#endif
k=Multiply(pa,ppdf,w);
}
return(k);
}