ba237a9d91
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
68 lines
1.0 KiB
C
Executable File
68 lines
1.0 KiB
C
Executable File
/* DEC *ConvFractionToDecimal( x, i, n, d)
|
|
*
|
|
* ARGUMENT
|
|
* DEC *x; output
|
|
* long i; integer part
|
|
* int n; numerator
|
|
* int d; denominator
|
|
*
|
|
* DESCRIPTION
|
|
* Sets x equal to the fraction i + n/d.
|
|
*
|
|
* SIDE EFFECTS
|
|
* x is indeterminate on error.
|
|
*
|
|
* RETURNS
|
|
* The DEC if the conversion is successful, and GM_NULL otherwise.
|
|
*
|
|
* POSSIBLE ERROR CODES
|
|
* GM_NULLPOINTER
|
|
* GM_DIV0
|
|
*
|
|
* AUTHOR
|
|
* Jared Levy Oct. 10, 1989
|
|
* Copyright (C) 1989-1990 Greenleaf Software Inc. All rights reserved.
|
|
*
|
|
* MODIFICATIONS
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "gmsystem.h"
|
|
|
|
DEC *ConvFractionToDecimal( x, i, n, d)
|
|
DEC *x;
|
|
long i;
|
|
int n;
|
|
int d;
|
|
{
|
|
int isneg=0;
|
|
|
|
_MacStart(GM_FRTOD);
|
|
_MacOutVarD(x);
|
|
|
|
/* check for 0 denominator */
|
|
if (!d) {
|
|
_MacErr(GM_DIV0);
|
|
_MacRet(GM_NULL);
|
|
}
|
|
|
|
/* handle negative numbers */
|
|
if (i<0) {
|
|
isneg = 1;
|
|
i = -i;
|
|
n = (n<0) ? -n : n;
|
|
d = (d<0) ? -d : d;
|
|
}
|
|
|
|
ConvLongToDecimal(x, (long) n);
|
|
DivideDecimalByLong(x, x, (long) d);
|
|
AddLongToDecimal(x, x, i);
|
|
|
|
DeleteTrailingZeroes(x, x);
|
|
|
|
x->dc.attr = isneg;
|
|
|
|
_MacRet(x);
|
|
}
|