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
		
			
				
	
	
		
			86 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| /* DEC	*TruncateCents(pDst,pSrc1,cents)
 | |
|  *
 | |
|  * ARGUMENT
 | |
|  *	pDst is	a pointer to the destination DEC structure.
 | |
|  *	pSrc1 is a ptr to the source1 DEC structure.
 | |
|  *	cents is the int number	of cents to Truncate to
 | |
|  *
 | |
|  * DESCRIPTION
 | |
|  *	Truncates pSrc1	to the nearest cents pennies, storing result in	pDst.
 | |
|  *   For example, if cents == 5, Truncates to the nearest nickle.
 | |
|  *   The result	always has two decimal places.
 | |
|  *
 | |
|  * SIDE	EFFECTS
 | |
|  *	pSrc1 remains unchanged	and pDst is undefined on error.
 | |
|  *
 | |
|  * RETURNS
 | |
|  *	Returns	a pointer to the pDst structure	unless error,
 | |
|  *   in	which case it returns a	NULL(a C false). On error, the error
 | |
|  *   is	in wGMError, unless an error was already there.
 | |
|  *
 | |
|  * POSSIBLE ERROR CODES
 | |
|  *
 | |
|  *	GM_NULLPOINTER
 | |
|  *	GM_ARGVAL
 | |
|  *	GM_OVERFLOW
 | |
|  *	GM_UNDERFLOW
 | |
|  *
 | |
|  * AUTHOR
 | |
|  * Jared Levy	10/1/89
 | |
|  *   Copyright (C) 1989-1990 Greenleaf Software	Inc.  All rights reserved.
 | |
|  *
 | |
|  * MODIFICATIONS
 | |
|  *
 | |
| */
 | |
| 
 | |
| #include <stdio.h>
 | |
| #include "gm.h"
 | |
| #include "gmsystem.h"
 | |
| 
 | |
| DEC	*TruncateCents(pDst,pSrc1,cents)
 | |
| DEC	*pDst, *pSrc1;
 | |
| int	cents;
 | |
| {
 | |
| 	register int	r;
 | |
| 	unsigned long	i;
 | |
| 	DEC	*p, dtmp, *tmp=&dtmp;
 | |
| 
 | |
| 	_MacStart(GM_TRUNCCNT);
 | |
| 
 | |
| 	if (cents<=0)  {
 | |
| 		_MacErr(GM_ARGVAL);
 | |
| 		_MacRet(GM_NULL);
 | |
| 	}
 | |
| 
 | |
| 	_MacOutVarD(pDst);
 | |
| 
 | |
| 	/* Truncate to two decimals */
 | |
| 	p = TruncateDecimal(tmp, pSrc1,	2);
 | |
| 
 | |
| 	if (!p)	 {
 | |
| 		_MacRet(GM_NULL);
 | |
| 	}
 | |
| 
 | |
| 	_MacDCopy(pDst,	tmp);
 | |
| 	if (_MacIsDecZ(tmp))  {
 | |
| 		_MacRet(pDst);
 | |
| 	}
 | |
| 
 | |
| 	/* determine remainder of division */
 | |
| 	r = _DivUnsArrByUns(tmp->dc.sl,	cents, 5);
 | |
| 	if (r==0)  {
 | |
| 		_MacRet(pDst);
 | |
| 	}
 | |
| 
 | |
| 	/* Truncate down to nearest multiple */
 | |
| 		i = (unsigned long) r;
 | |
| 		if (pDst->ls.lsl[0] < i)
 | |
| 			pDst->ls.lsl[1]	--;
 | |
| 		pDst->ls.lsl[0]	-= i;
 | |
| 		if (_MacIsDecZ(pDst))
 | |
| 			_MacErr(GM_UNDERFLOW);
 | |
| 
 | |
| 	_MacRet(pDst);
 | |
| 
 | |
| }
 |