3 /* Copyright (c) 1994 Stanford University
7 This software is provided under the terms described in
8 the "suif_copyright.h" include file. */
10 #include <suif_copyright.h>
12 /* Fraction Implementation */
13 #define _MODULE_ "libsuifmath.a"
14 #pragma implementation "fract.h"
20 /* Reduce the fraction. */
26 else if (n
== 1 && d
> 0) ;
32 void fract::reduce_aux()
34 /* convert to absolute values */
35 int mm
= (n
< 0) ? -n
: n
;
36 int nn
= (d
< 0) ? -d
: d
;
38 /* find gcd and divide thru by it */
41 if (rr
== 0) break; /* nn is the answer */
52 fract
fract::operator/(const fract
&a
) const
56 /* get the reciprocal */
59 rcp
= fract(fneg(a
.denom()), fneg(a
.num()));
61 rcp
= fract(a
.denom(), a
.num());
64 /* multiply by the reciprocal */
70 void fract::print(FILE *f
) const
73 fprintf(f
, " %d ", n
);
75 fprintf(f
, "%d/%d", n
, d
);