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

87 lines
1.4 KiB
C
Executable File

/*int _DivProcRnd(c,a,b,ida,idb,nid)
*
* ARGUMENT
* DEC *c;
* unsigned a[], b[];
* int ida,idb,nid;
*
* DESCRIPTION
* This routine divides one positive DEC structure by another, setting
* dst = src1 / src2.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* GM_SUCCESS or error code.
*
* ALGORITHM
* a = an * 10^-ad
* b = bn * 10^-bd
* c = a / b
* c = (10^p * an / bn) * 10^[-(ad - bd + p)]
* cn = 10^p * an / bn, cd = ad - bd + p
*
* AUTHOR
* Jared Levy 05-JAN-1987 17:30
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
*
* MODIFICATIONS
*
*/
#include <stdio.h>
#include "gm.h"
#include "gmsystem.h"
int _DivProcRnd(c,a,b,ida,idb,nid)
DEC *c;
unsigned SHORT a[], b[];
int ida,idb,nid;
{
int i, p;
unsigned SHORT *cn, ad[5];
/* sets c = a / b,
where a and b are positive DEC numbers, and the result is stored in c */
cn = c->dc.sl;
p = nid - (ida - idb);
a[5] = 0;
a[6] = 0;
a[7] = 0;
a[8] = 0;
a[9] = 0;
a[10]= 0;
a[11]= 0;
if (p<0)
_DivUnsArrByPwrOf10(a,5,-p);
if (p>0) {
i = _MulUnsArrByPwrOf10(a,p,10);
/* check for overflow */
ad[0]=a[5];
ad[1]=a[6];
ad[2]=a[7];
ad[3]=a[8];
ad[4]=a[9];
_DoubleUnsArr(ad, 5);
if (a[4]&0x8000)
ad[0]=ad[0]+1;
if (!((i == GM_SUCCESS) &&
(_CompareUnsArr(ad,b,5) == -1)))
return(GM_OVERFLOW);
}
_DivUns10ArrByUns5Arr(cn, a, b);
c->dc.id = nid;
return(GM_SUCCESS);
}