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
62 lines
880 B
C
Executable File
62 lines
880 B
C
Executable File
/* DEC *Factorial(pDst, n)
|
|
*
|
|
* ARGUMENT
|
|
* DEC *pDst;
|
|
* unsigned n;
|
|
*
|
|
* DESCRIPTION
|
|
* Sets pDst = n!
|
|
*
|
|
* SIDE EFFECTS
|
|
* None.
|
|
*
|
|
* RETURNS
|
|
* pDst if successful, GM_NULL otherwise
|
|
*
|
|
* POSSIBLE ERRORS
|
|
* GM_NOMEMORY
|
|
* GM_OVERFLOW (if n > 20)
|
|
*
|
|
* AUTHOR
|
|
* Jared Levy
|
|
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
|
|
*
|
|
* MODIFICATIONS
|
|
*
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "gm.h"
|
|
#include "gmsystem.h"
|
|
|
|
DEC *Factorial(pDst, n)
|
|
DEC *pDst;
|
|
unsigned n;
|
|
{
|
|
DEC dmult, *mult = &dmult;
|
|
unsigned i;
|
|
|
|
_MacStart(GM_DFACT);
|
|
|
|
_MacOutVarD(pDst);
|
|
|
|
/* check for overflow */
|
|
if (n > 20) {
|
|
_MacErr(GM_OVERFLOW);
|
|
_MacRet(GM_NULL);
|
|
}
|
|
|
|
/* do calculations */
|
|
_MacDCopy(pDst, &decOne);
|
|
_MacDCopy(mult, &decOne);
|
|
|
|
for (i=2; i<=n; i++) {
|
|
mult->dc.sl[0] = i;
|
|
_MulDec80Bit(pDst, pDst, mult);
|
|
}
|
|
|
|
/* pDst fits into 64 bits */
|
|
_MacRet(pDst);
|
|
}
|