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
		
			
				
	
	
		
			104 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			104 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
/* DEC	*RootInteger(pDst,pSrc1,n)
 | 
						|
 *
 | 
						|
 * ARGUMENT
 | 
						|
 *	DEC	*pDst,*pSrc1;
 | 
						|
 *	int	n;
 | 
						|
 *
 | 
						|
 * DESCRIPTION
 | 
						|
 *	Calculates the n'th root of pSrc1 and returns the answer in pDst.
 | 
						|
 *  This provides an x**(1/n) power function for DEC numbers.
 | 
						|
 *
 | 
						|
 * SIDE	EFFECTS
 | 
						|
 *	None.
 | 
						|
 *
 | 
						|
 * RETURNS
 | 
						|
 *	Pointer	to the result if no error, otherwise GM_NULL.
 | 
						|
 *
 | 
						|
 * ALGORITHM:
 | 
						|
 *	x**(1/n) = e**(ln(x)/n).
 | 
						|
 *
 | 
						|
 * POSSIBLE ERROR CODES
 | 
						|
 *
 | 
						|
 *	GM_NULLPOINTER
 | 
						|
 *	GM_OVERFLOW
 | 
						|
 *	GM_UNDERFLOW
 | 
						|
 *	GM_IMAG
 | 
						|
 *	GM_PWR0
 | 
						|
 *	GM_DIV0
 | 
						|
 *
 | 
						|
 * AUTHOR
 | 
						|
 *  Andy Anderson   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"
 | 
						|
 | 
						|
DEC	*RootInteger(pDst,pSrc,n)
 | 
						|
DEC	*pDst, *pSrc;
 | 
						|
int	n;
 | 
						|
{
 | 
						|
	DEC	temp, *pt, *nsrc, dnsrc, ddn, *dn=&ddn;
 | 
						|
	int	i, isn=0;
 | 
						|
 | 
						|
	_MacStart(GM_DROOTI);
 | 
						|
	_MacInVarD(pSrc);
 | 
						|
	_MacOutVarD(pDst);
 | 
						|
 | 
						|
	if (_MacIsDecZ(pSrc))  {
 | 
						|
		if (n>0)  {
 | 
						|
			_MacDZero(pDst);
 | 
						|
			_MacRet(pDst);
 | 
						|
		}
 | 
						|
		else  {
 | 
						|
			_MacErr(GM_PWR0);
 | 
						|
			_MacRet(GM_NULL);
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	if (_MacIsDecN(pSrc))  {
 | 
						|
		if ((n % 2) == 0)  {
 | 
						|
			_MacErr(GM_IMAG);
 | 
						|
			_MacRet(GM_NULL);
 | 
						|
		}
 | 
						|
		isn=1;
 | 
						|
		nsrc = &dnsrc;
 | 
						|
		_MacDCopy(nsrc,pSrc);
 | 
						|
		pSrc=nsrc;
 | 
						|
		_MacDChgs(nsrc);
 | 
						|
	}
 | 
						|
 | 
						|
	pt = &temp;
 | 
						|
 | 
						|
	(void) _LnDec80Bit(pt, pSrc);
 | 
						|
 | 
						|
	(void) ConvLongToDecimal(dn, (long) n);
 | 
						|
	(void) _DivDec80Bit(pt,	pt, dn);
 | 
						|
 | 
						|
	i = _ExpDec80Bit(pt, pt);
 | 
						|
	if(i==GM_OVERFLOW) {
 | 
						|
		_MacErr(i);
 | 
						|
		_MacRet(GM_NULL);
 | 
						|
		}
 | 
						|
 | 
						|
	i = _Sq5UnsTo4Uns(pt);
 | 
						|
	if(i!=GM_SUCCESS) {
 | 
						|
		_MacErr(GM_OVERFLOW);
 | 
						|
		_MacRet(GM_NULL);
 | 
						|
	}
 | 
						|
 | 
						|
	if (_MacIsDecZ(pt))  {
 | 
						|
		_MacErr(GM_UNDERFLOW);
 | 
						|
	}
 | 
						|
 | 
						|
	if (isn)
 | 
						|
		_MacDChgs(pt);
 | 
						|
 | 
						|
	_MacDCopy(pDst,pt);
 | 
						|
	_MacRet(pDst);
 | 
						|
}
 |