Patch level :2.1 nopatch

Files correlati     :gfm.dll
Ricompilazione Demo : [ ]
Commento            :riportate sulla 2.1 le correzioni sulla gfm.dll della 2.0


git-svn-id: svn://10.65.10.50/trunk@11815 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
luca 2004-03-09 09:49:17 +00:00
parent ac70ddd888
commit 3d88151f4d
16 changed files with 212 additions and 378 deletions

View File

@ -26,24 +26,13 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
int _AddUnsArrToUnsArr(src1, src2, dst, n) int _AddUnsArrToUnsArr(src1, src2, dst, n)
unsigned SHORT src1[], src2[], dst[]; unsigned SHORT src1[], src2[], dst[];
int n; int n;
{ {
int i; int i;
unsigned long pdst,maxunsint; unsigned long pdst;
unsigned carry; unsigned carry = 0;
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) if (n>0)
{ {
@ -51,10 +40,10 @@ int n;
{ {
pdst=carry+(unsigned long)src1[i]; pdst=carry+(unsigned long)src1[i];
pdst+=(unsigned long)src2[i]; pdst+=(unsigned long)src2[i];
if (pdst>maxunsint) if (pdst>MAXUNSINT)
{ {
carry=(unsigned)(pdst >> BITSPERUI ); carry=(unsigned)(pdst >> BITSPERUI );
dst[i]=(unsigned SHORT )(pdst & maxunsint ); dst[i]=(unsigned SHORT )(pdst & MAXUNSINT );
} }
else else
{ {

View File

@ -17,6 +17,7 @@
* *
* AUTHOR * AUTHOR
* Brugnoli Giugno 1992 * Brugnoli Giugno 1992
* Bonazzi Febbraio 2002
* *
* MODIFICATIONS * MODIFICATIONS
* *
@ -31,21 +32,19 @@ unsigned SHORT a[],c;
int n; int n;
{ {
int i; int i;
unsigned SHORT rem,qt; unsigned SHORT rem = 0,qt;
unsigned long remup,ntbd; unsigned long remup,ntbd;
rem=0; if ((c) && (n))
{
if ((c)&&(n)) for (i = n-1; i >= 0;i--)
{ {
for (i=n-1;i>=0;i--) remup = (long)rem << BITSPERUI;
{ ntbd = (long)a[i] + remup;
remup=(long)rem<<BITSPERUI; qt = (unsigned SHORT)(ntbd / c);
ntbd=(long)a[i]+remup; rem = (unsigned SHORT)(ntbd % c);
qt=(unsigned SHORT)(ntbd / c); a[i] = qt;
rem=(unsigned SHORT)(ntbd % c);
a[i]=qt;
}
} }
return(rem); }
return(rem);
} }

View File

@ -29,100 +29,81 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
void _DivUnsArrByUnsArr(c,a,m,b,n,rf) void _DivUnsArrByUnsArr(c,a,m,b,n,rf)
unsigned SHORT a[],c[],b[]; unsigned SHORT a[],c[],b[];
int n,m,rf; int n,m,rf;
{ {
int i,j,k,nc,ft = 0; int i,j,k,nc,ft = 0;
unsigned long maxunsint,dvd,pqt,pp; unsigned long dvd,pqt,pp;
float nqt; float nqt;
unsigned SHORT copa[10],copb[10],af[10],ppt[10],ppd[10],pqa[2]; unsigned SHORT copa[10],copb[10],af[10],ppt[10],ppd[10],pqa[2];
#ifdef SH_LIB
maxunsint=1;
for (i=1;i<=BITSPERUI;i++) maxunsint*=2;
maxunsint--;
#else
maxunsint=(unsigned long)pow(2.,(double)BITSPERUI)-1;
#endif
for(j=0;j<10;j++) for(j=0;j<10;j++)
{
af[j]=copa[j]=copb[j]=0; af[j]=copa[j]=copb[j]=0;
}
for(j=0;j<n;j++) for(j=0;j<n;j++)
{
copb[j]=b[j]; copb[j]=b[j];
}
for(j=0;j<m;j++) for(j=0;j<m;j++)
{
copa[j]=a[j]; copa[j]=a[j];
}
for(j=0;j<5;j++) for(j=0;j<5;j++)
{
c[j]=0; c[j]=0;
}
copa[m]=0; copa[m]=0;
nc=m; nc=m;
af[0]=1; af[0]=1;
for(i=m-n;i>=0;i--) for(i=m-n;i>=0;i--)
{ {
dvd=(long)copa[nc]*(maxunsint+1)+(long)copa[nc-1]; dvd=(long)copa[nc]*(MAXUNSINT+1)+(long)copa[nc-1];
pqt=dvd/copb[n-1]; pqt=dvd/copb[n-1];
pqa[1]=(unsigned SHORT)(pqt>>16); pqa[1]=(unsigned SHORT)(pqt>>16);
pqa[0]=(unsigned SHORT)(pqt&maxunsint); pqa[0]=(unsigned SHORT)(pqt&MAXUNSINT);
for(j=0;j<10;j++) for(j=0;j<10;j++)
{
ppd[j]=((j>n-1)?0:copb[j]); ppd[j]=((j>n-1)?0:copb[j]);
}
for(j=1;j<=i;j++) for(j=1;j<=i;j++)
{ {
for(k=9;k>=1;k--) for(k=9;k>=1;k--)
{
ppd[k]=ppd[k-1]; ppd[k]=ppd[k-1];
}
ppd[0]=0; ppd[0]=0;
} }
_MulUnsArrByUnsArr(ppd,pqa,ppt,10,2,ft); _MulUnsArrByUnsArr(ppd,pqa,ppt,10,2,ft);
if (_CompareUnsArr(copa,ppt,nc+1)==-1) if (_CompareUnsArr(copa,ppt,nc+1)==-1)
{ {
pp=(long)ppt[nc]*(maxunsint+1)+(long)ppt[nc-1]; pp=(long)ppt[nc]*(MAXUNSINT+1)+(long)ppt[nc-1];
nqt=(float)dvd; nqt=(float)dvd;
nqt/=(float)pp; nqt/=(float)pp;
nqt*=(float)pqt; nqt*=(float)pqt;
nqt+=(float)5; nqt+=(float)5;
#ifndef SH_LIB // Brugnoli was HERE
pqa[1]=(unsigned SHORT)((long int)nqt>>16); pqa[1]=(unsigned SHORT)(((long int)nqt) >> BITSPERUI);
pqa[0]=(unsigned SHORT)((long int)nqt&maxunsint); pqa[0]=(unsigned SHORT)(((long int)nqt) & MAXUNSINT);
#endif
_MulUnsArrByUnsArr(ppd,pqa,ppt,10,2,ft); _MulUnsArrByUnsArr(ppd,pqa,ppt,10,2,ft);
} }
while (_CompareUnsArr(copa,ppt,nc+1)==-1)
{ while (_CompareUnsArr(copa,ppt,nc+1)==-1)
{
_SubUnsArr(pqa,af,2); _SubUnsArr(pqa,af,2);
_MulUnsArrByUnsArr(ppd,pqa,ppt,10,2,ft); _MulUnsArrByUnsArr(ppd,pqa,ppt,10,2,ft);
} }
c[i]=pqa[0]; c[i]=pqa[0];
_SubUnsArr(copa,ppt,m); _SubUnsArr(copa,ppt,m);
nc--; nc--;
} }
/* qui copa Š = al resto della divisione!! */ /* qui copa Š = al resto della divisione!! */
if (rf) if (rf)
{ {
_SubUnsArr(copb,af,n); _SubUnsArr(copb,af,n);
_HalveUnsArr(copb,n); _HalveUnsArr(copb,n);
if (_CompareUnsArr(copa,copb,m)==1) if (_CompareUnsArr(copa,copb,m)==1)
{
_IncrementUnsArr(c); _IncrementUnsArr(c);
} }
}
} }

View File

@ -27,24 +27,23 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
void _DivUnsArrByPwrOf10(a,n,p) void _DivUnsArrByPwrOf10(a,n,p)
unsigned SHORT a[]; unsigned SHORT a[];
int n,p; int n,p;
{ {
int ppdf;
while (p>4) while (p>4)
{ {
_DivUnsArrByUns(a,10000,n); _DivUnsArrByUns(a,10000,n);
p-=4; p-=4;
} }
#ifdef SH_LIB
ppdf=1; switch (p)
for (i=1;i<=p;i++) ppdf*=10; {
#else case 0: _DivUnsArrByUnsRound(a,1,n); break;
ppdf=(int)pow(10.,(double)p); case 1: _DivUnsArrByUnsRound(a,10,n); break;
#endif case 2: _DivUnsArrByUnsRound(a,100,n); break;
_DivUnsArrByUnsRound(a,ppdf,n); case 3: _DivUnsArrByUnsRound(a,1000,n); break;
case 4: _DivUnsArrByUnsRound(a,10000,n); break;
default: break;
}
} }

View File

@ -27,27 +27,23 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
void _DivUnsArrByPwrOf10Trunc(a,n,p) void _DivUnsArrByPwrOf10Trunc(a,n,p)
unsigned SHORT a[]; unsigned SHORT a[];
int n,p; int n,p;
{ {
int ppdf;
while (p>4) while (p>4)
{ {
_DivUnsArrByUns(a,10000,n); _DivUnsArrByUns(a,10000,n);
p-=4; p-=4;
} }
#ifdef SH_LIB
ppdf=1;
for (i=1;i<=p;i++) ppdf*=10;
#else
ppdf=(int)pow(10.,(double)p);
#endif
_DivUnsArrByUns(a,ppdf,n);
switch (p)
{
case 0: _DivUnsArrByUns(a,1,n); break;
case 1: _DivUnsArrByUns(a,10,n); break;
case 2: _DivUnsArrByUns(a,100,n); break;
case 3: _DivUnsArrByUns(a,1000,n); break;
case 4: _DivUnsArrByUns(a,10000,n); break;
default: break;
}
} }

View File

@ -32,20 +32,19 @@ extern double pow(double, double);
void _DivUnsArrByPwrOf10Trunc(unsigned SHORT a[],int n,int p) void _DivUnsArrByPwrOf10Trunc(unsigned SHORT a[],int n,int p)
{ {
int ppdf;
while (p>4) while (p>4)
{ {
_DivUnsArrByUns(a,10000,n); _DivUnsArrByUns(a,10000,n);
p-=4; p-=4;
} }
#ifdef SH_LIB
ppdf=1;
for (i=1;i<=p;i++) ppdf*=10;
#else
ppdf=(int)pow(10.,(double)p);
#endif
_DivUnsArrByUns(a,ppdf,n);
case (p)
{
case 0: _DivUnsArrByUns(a,1,n); break;
case 1: _DivUnsArrByUns(a,10,n); break;
case 2: _DivUnsArrByUns(a,100,n); break;
case 3: _DivUnsArrByUns(a,1000,n); break;
case 4: _DivUnsArrByUns(a,10000,n); break;
default:
}
} }

View File

@ -26,47 +26,32 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
unsigned _DoubleUnsArr(a,n) unsigned _DoubleUnsArr(a,n)
unsigned SHORT a[]; unsigned SHORT a[];
int n; int n;
{ {
int i; int i;
unsigned long maxunsint,pdst; unsigned long pdst;
unsigned SHORT carry; unsigned SHORT carry = 0;
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) if (n>0)
{ {
for (i=0;i<n;i++) for (i=0;i<n;i++)
{ {
pdst=carry+(unsigned long)a[i]*2; pdst=carry+(unsigned long)a[i]*2;
if (pdst>maxunsint) if (pdst>MAXUNSINT)
{ {
carry=(unsigned SHORT)(pdst>> BITSPERUI ); carry=(unsigned SHORT)(pdst>> BITSPERUI );
a[i]=(unsigned SHORT)(pdst & maxunsint ); a[i]=(unsigned SHORT)(pdst & MAXUNSINT );
} }
else else
{ {
a[i]=(unsigned SHORT)pdst; a[i]=(unsigned SHORT)pdst;
carry=0; carry=0;
} }
}
if ((a[n-1])>>(BITSPERUI-1))
{
return(FAILURE);
}
else
{
return(GM_SUCCESS);
}
} }
if ((a[n-1]) >> (BITSPERUI-1))
return(FAILURE);
}
return(GM_SUCCESS);
} }

View File

@ -1,2 +1,4 @@
#define BITSPERUI 16 #define BITSPERUI 16
#define SHORT short #define SHORT short
#define MAXUNSINT (unsigned long)((1L<<BITSPERUI)-1)

View File

@ -57,7 +57,12 @@ extern DEC decPoint01;
extern "C" { extern "C" {
#endif #endif
#define SHORT short //#ifdef M_I386
//#define SHORT short
//#else
//#define SHORT int
//#endif
int _AddDec80Bit( DEC *, DEC *, DEC *); int _AddDec80Bit( DEC *, DEC *, DEC *);
int GF_CDECL _AddUnsArrToUnsArr( unsigned SHORT [], unsigned SHORT [], int GF_CDECL _AddUnsArrToUnsArr( unsigned SHORT [], unsigned SHORT [],

View File

@ -37,49 +37,36 @@ int n,m,tmp1;
{ {
int i,j; int i,j;
unsigned long apdst[10]; unsigned long apdst[10];
unsigned long pdst,maxunsint; unsigned long pdst;
tmp1=0; tmp1=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
for(i=0;i<10;i++) for(i=0;i<10;i++)
{
apdst[i]=0; apdst[i]=0;
}
for(i=0;i<n;i++) for(i=0;i<n;i++)
{ {
for(j=0;j<m;j++) for(j=0;j<m;j++)
{ {
pdst=(unsigned long)src1[j]*(unsigned long)src2[i]; pdst=(unsigned long)src1[j]*(unsigned long)src2[i];
if (pdst>maxunsint) if (pdst>MAXUNSINT)
{
apdst[i+j+1]+=(unsigned long)(pdst>>BITSPERUI);
apdst[i+j]+=(unsigned long)(pdst&maxunsint);
}
else
{
apdst[i+j]+=(unsigned long)pdst;
}
}
}
for(i=0;i<10;i++)
{
if (apdst[i]>maxunsint)
{ {
apdst[i+1]+=(unsigned long)(apdst[i]>>BITSPERUI); apdst[i+j+1]+=(unsigned long)(pdst>>BITSPERUI);
apdst[i]=(unsigned long)(apdst[i]&maxunsint); apdst[i+j]+=(unsigned long)(pdst&MAXUNSINT);
} }
else
apdst[i+j]+=(unsigned long)pdst;
} }
}
for(i=0;i<10;i++) for(i=0;i<10;i++)
{
if (apdst[i]>MAXUNSINT)
{ {
dst[i]=(unsigned SHORT)apdst[i]; apdst[i+1]+=(unsigned long)(apdst[i]>>BITSPERUI);
apdst[i]=(unsigned long)(apdst[i]&MAXUNSINT);
} }
}
for(i=0;i<10;i++)
dst[i]=(unsigned SHORT)apdst[i];
} }

View File

@ -27,42 +27,29 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
void _MulUnsArr(src1, dst, num, n) void _MulUnsArr(src1, dst, num, n)
unsigned SHORT src1[], dst[], num; unsigned SHORT src1[], dst[], num;
int n; int n;
{ {
int i; int i;
unsigned long pdst[10],maxunsint; unsigned long pdst[10];
unsigned SHORT carry; unsigned SHORT 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
carry=0;
for (i=0;i<n;i++) for (i=0;i<n;i++)
{
pdst[i]=(unsigned long)src1[i]*num; pdst[i]=(unsigned long)src1[i]*num;
}
for (i=0;i<n;i++) for (i=0;i<n;i++)
{ {
pdst[i]+=carry; pdst[i]+=carry;
if (pdst[i]>maxunsint) if (pdst[i]>MAXUNSINT)
{ {
carry=(unsigned SHORT)(pdst[i]>>BITSPERUI); carry=(unsigned SHORT)(pdst[i]>>BITSPERUI);
dst[i]=(unsigned SHORT)(pdst[i]&maxunsint); dst[i]=(unsigned SHORT)(pdst[i]&MAXUNSINT);
} }
else else
{ {
carry=0; carry=0;
dst[i]=(unsigned SHORT)pdst[i]; dst[i]=(unsigned SHORT)pdst[i];
}
} }
}
} }

View File

@ -26,44 +26,31 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
int Multiply(sr,num,m) int Multiply(sr,num,m)
unsigned SHORT sr[],num; unsigned SHORT sr[],num;
int m; int m;
{ {
int i; int i;
unsigned long pdst[10],maxunsint; unsigned long pdst[10];
unsigned SHORT carry; unsigned SHORT 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
carry=0;
for (i=0;i<m;i++) for (i=0;i<m;i++)
{
pdst[i]=(unsigned long)sr[i]*num; pdst[i]=(unsigned long)sr[i]*num;
}
for (i=0;i<m;i++) for (i=0;i<m;i++)
{ {
pdst[i]+=carry; pdst[i]+=carry;
if (pdst[i]>maxunsint) if (pdst[i]>MAXUNSINT)
{ {
carry=(unsigned SHORT)(pdst[i]>>BITSPERUI); carry=(unsigned SHORT)(pdst[i]>>BITSPERUI);
sr[i]=(unsigned SHORT)(pdst[i]&maxunsint); sr[i]=(unsigned SHORT)(pdst[i]&MAXUNSINT);
} }
else else
{ {
carry=0; carry=0;
sr[i]=(unsigned SHORT)pdst[i]; sr[i]=(unsigned SHORT)pdst[i];
}
} }
}
return( (carry)? GM_OVERFLOW : GM_SUCCESS ); return( (carry)? GM_OVERFLOW : GM_SUCCESS );
} }
@ -72,32 +59,28 @@ int _MulUnsArrByPwrOf10(pa,n,w)
unsigned SHORT pa[]; unsigned SHORT pa[];
int n,w; int n,w;
{ {
int k=GM_SUCCESS;
int ppdf,k;
k=GM_SUCCESS;
if (n>47) if (n>47)
{ return GM_OVERFLOW;
k=GM_OVERFLOW;
}
while ((n>4)&&(k==GM_SUCCESS)) while (n>4)
{ {
k=Multiply(pa,10000,w); k = Multiply(pa,10000,w);
if (k != GM_SUCCESS)
return k;
n-=4; n-=4;
} }
if (k!=GM_OVERFLOW) switch (n)
{ {
#ifdef SH_LIB case 0: k=Multiply(pa,1,w); break;
ppdf=1; case 1: k=Multiply(pa,10,w); break;
for (i=1;i<=n;i++) ppdf*=10; case 2: k=Multiply(pa,100,w); break;
#else case 3: k=Multiply(pa,1000,w); break;
ppdf=(int)pow(10.,(double)n); case 4: k=Multiply(pa,10000,w); break;
#endif default: break;
k=Multiply(pa,ppdf,w); }
}
return(k); return(k);

View File

@ -26,44 +26,32 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
int Mltply(sr,num,m) int Mltply(sr,num,m)
unsigned SHORT sr[],num; unsigned SHORT sr[],num;
int m; int m;
{ {
int i; int i;
unsigned long pdst[10],maxunsint; unsigned long pdst[10];
unsigned SHORT carry; unsigned SHORT 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
carry=0;
for (i=0;i<m;i++) for (i=0;i<m;i++)
{
pdst[i]=(unsigned long)sr[i]*num; pdst[i]=(unsigned long)sr[i]*num;
}
for (i=0;i<m;i++) for (i=0;i<m;i++)
{ {
pdst[i]+=carry; pdst[i]+=carry;
if (pdst[i]>maxunsint) if (pdst[i]>MAXUNSINT)
{ {
carry=(unsigned SHORT)(pdst[i]>>BITSPERUI); carry=(unsigned SHORT)(pdst[i]>>BITSPERUI);
sr[i]=(unsigned SHORT)(pdst[i]&maxunsint); sr[i]=(unsigned SHORT)(pdst[i]&MAXUNSINT);
} }
else else
{ {
carry=0; carry=0;
sr[i]=(unsigned SHORT)pdst[i]; sr[i]=(unsigned SHORT)pdst[i];
}
} }
}
return( ((carry)||(sr[m-1]>>(BITSPERUI-1)))? GM_OVERFLOW : GM_SUCCESS ); return( ((carry)||(sr[m-1]>>(BITSPERUI-1)))? GM_OVERFLOW : GM_SUCCESS );
} }
@ -73,60 +61,39 @@ unsigned SHORT pa[];
int c; int c;
{ {
int ppdf,k,i; int ppdf = 10, i;
unsigned long maxunsint,pdst,carry; unsigned long pdst, carry = c;
unsigned SHORT dst[10]; unsigned SHORT dst[10];
k=GM_SUCCESS; for (i=0;i<=4;i++)
#ifdef SH_LIB dst[i] = pa[i];
maxunsint=1; for (i=5;i<=9;i++)
for (i=1;i<=BITSPERUI;i++) maxunsint*=2; dst[i] = 0;
maxunsint--;
#else if (Mltply(dst,ppdf,5) == GM_OVERFLOW)
maxunsint=(unsigned long)pow(2.,(float)BITSPERUI)-1; return GM_OVERFLOW;
#endif
ppdf=10; for (i = 0 ; carry && (i <= 9); i++)
for (i=0;i<=9;i++) {
pdst=(long)dst[i]+(long)carry;
if (pdst>MAXUNSINT)
{ {
dst[i]=(i<5?pa[i]:0); carry=(pdst>>BITSPERUI);
dst[i]=(unsigned SHORT)(pdst&MAXUNSINT);
} }
k=Mltply(dst,ppdf,5); else
i=0;
carry=c;
if (k!=GM_OVERFLOW)
{ {
do dst[i]=(unsigned SHORT)pdst;
{ carry=0;
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) if (i>5) // va bene o dovrebbe essere 4
{ return GM_OVERFLOW;
k=GM_OVERFLOW;
}
if (!k) for (i=0;i<5;i++)
{ pa[i]=dst[i];
for (i=0;i<5;i++)
{
pa[i]=dst[i];
}
}
return(k); return(GM_SUCCESS);
} }

View File

@ -42,9 +42,6 @@
#include <malloc.h> #include <malloc.h>
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
#ifdef SH_LIB
#include "import.h"
#endif
int _ScanfAux(int wOpt,char * sBuffer, char * sFmt, ELLIPSES) int _ScanfAux(int wOpt,char * sBuffer, char * sFmt, ELLIPSES)
{ {

View File

@ -26,52 +26,27 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
int _SubUnsArrFromUnsArr(src1, src2, dst, n) int _SubUnsArrFromUnsArr(src1, src2, dst, n)
unsigned SHORT src1[], src2[], dst[]; unsigned SHORT src1[], src2[], dst[];
int n; int n;
{ {
int i; int i;
unsigned long psrc,maxunsint; unsigned long psrc;
unsigned SHORT carry; unsigned SHORT carry = 0;
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) if (n>0)
{ {
for (i=0;i<n;i++) 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;
}
dst[i]=(unsigned SHORT)(psrc-(unsigned long)src2[i]);
}
if (carry)
{
return(GM_FAILURE);
}
else
{
return(GM_SUCCESS);
}
}
else
{ {
return(GM_SUCCESS); psrc= (long)src1[i] - (long)carry;
carry = src2[i] > src1[i] ? 1 : 0;
if (carry)
psrc += MAXUNSINT+0x1L;
dst[i]=(unsigned SHORT)(psrc-(unsigned long)src2[i]);
} }
if (carry)
return(GM_FAILURE);
}
return(GM_SUCCESS);
} }

View File

@ -27,40 +27,23 @@
#include "gm.h" #include "gm.h"
#include "gmsystem.h" #include "gmsystem.h"
extern double pow(double, double);
void _SubUnsArr(src1, src2, n) void _SubUnsArr(src1, src2, n)
unsigned SHORT src1[], src2[]; unsigned SHORT src1[], src2[];
int n; int n;
{ {
int i; int i;
unsigned long psrc,maxunsint; unsigned long psrc;
unsigned SHORT carry; unsigned SHORT carry = 0;
carry=0; if (n > 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++) for (i=0;i<n;i++)
{ {
if (src2[i]>src1[i]) psrc=(long)src1[i]-(long)carry;
{ carry = src2[i]>src1[i] ? 1 : 0;
psrc=maxunsint+0x1L+(long)src1[i]-(long)carry; if (carry)
carry=1; psrc += MAXUNSINT+0x1L;
}
else
{
psrc=src1[i]-carry;
carry=0;
}
src1[i]=(unsigned SHORT)(psrc-(unsigned long)src2[i]); src1[i]=(unsigned SHORT)(psrc-(unsigned long)src2[i]);
}
} }
}
} }