campo-sirio/gfm/dcoss.c

57 lines
1.0 KiB
C
Raw Normal View History

/* void _CosDecSmall(pDst,pSrc)
*
* ARGUMENT
* DEC *pDst, *pSrc;
*
* DESCRIPTION
* Sets pDst = cos(pSrc), where 0 <= pSrc < pi / 4.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* None.
*
* ALGORITHM
* Using the Taylor series,
* cos(x) = 1 - x^2/2! + x^4/4! - ...
*
* AUTHOR
* Jared Levy April 7, 1987
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
*
* MODIFICATIONS
*
*/
#include <stdio.h>
#include "gm.h"
#include "gmsystem.h"
void _CosDecSmall(pDst,pSrc)
DEC *pDst, *pSrc;
{
DEC *srcsq, dsrcsq, *term, dterm, *fact, dfact;
SHORT i;
srcsq = &dsrcsq;
(void) _MulDec80Bit(srcsq, pSrc, pSrc);
(void) ConvLongToDecimal(pDst, 1L);
term = &dterm;
(void) _MulDec80Bit(term, srcsq, &decPoint5);
i = 2;
fact = ConvLongToDecimal(&dfact, 6L);
while (!(_MacIsDecZ(term))) {
if ((i % 4) == 0)
(void) _AddDec80Bit(pDst, pDst, term);
else
(void) _SubDec80Bit(pDst, pDst, term);
i+=2;
_MulDec80Bit(term, term, srcsq);
fact->dc.sl[0] = i * (i - 1);
_DivRndDec80Bit(term, term, fact, 23);
}
}