Browse files

INFINITY seems to have problems compiling under darwin; it's probably

reserved.  So I replaced it with C_INF.

Also more makefile improvements.
  • Loading branch information...
1 parent 782b533 commit 7a0b9078a0e5985e65896888486cb22f98bbc7ef mjd committed Feb 1, 2005
Showing with 27 additions and 23 deletions.
  1. +6 −2 Makefile
  2. +3 −3 cf.c
  3. +1 −1 cf.h
  4. +6 −6 cf_arith.c
  5. +1 −1 cf_float.c
  6. +3 −3 cf_holo.c
  7. +1 −1 cf_rat.c
  8. +6 −6 libcf.3
View
8 Makefile
@@ -4,6 +4,10 @@ LIBS=-lm
default: demo
+HDRS= cf.h cf_arith.h cf_float.h cf_holo.h cf_it.h cf_rat.h
+SRCS= cf.c cf_arith.c cf_float.c cf_holo.c cf_it.c cf_rat.c main.c
+MANS= demo.1 libcf.3
+
cf.o: cf.c cf.h
cf_arith.o: cf_arith.c cf_arith.h cf.h
cf_float.o: cf_float.c cf_float.h cf.h
@@ -29,5 +33,5 @@ veryclean: clean
dist: cf.tgz
-cf.tgz:
- tar czvf cf.tgz *.[ch1-9]
+cf.tgz: $(SRCS) $(HDRS) $(MANS) Makefile
+ tar czf cf.tgz *.[ch1-9] Makefile
View
6 cf.c
@@ -26,13 +26,13 @@ int
next(CF cf) {
int t;
- if (cf->DONE) return INFINITY;
+ if (cf->DONE) return C_INF;
t = (cf->next)(cf);
if (t > TOOBIG) {
cf->DONE = 1;
- t = INFINITY;
+ t = C_INF;
}
return t;
@@ -51,7 +51,7 @@ fprint_cf(FILE *f, CF cf)
{
int t;
unsigned stop = STOP;
- while ((t = next(cf)) != INFINITY) {
+ while ((t = next(cf)) != C_INF) {
fprintf(f, "%d ", t);
if (--stop == 0) break;
}
View
2 cf.h
@@ -9,7 +9,7 @@ typedef struct st_cf {
} *CF;
#include <limits.h>
-#define INFINITY INT_MAX
+#define C_INF INT_MAX
#define TOOBIG 65535
#ifdef DEBUG
View
12 cf_arith.c
@@ -21,8 +21,8 @@ static void ingest_x(CFA);
static void ingest_y(CFA);
#define MAX(i, j) ((i) > (j) ? (i) : (j))
-#define IDIFF(p, q) ((p) == INFINITY ? INFINITY : \
- (q) == INFINITY ? INFINITY : \
+#define IDIFF(p, q) ((p) == C_INF ? C_INF : \
+ (q) == C_INF ? C_INF : \
fabs((p)-(q)))
CF
@@ -64,7 +64,7 @@ next_arith(CF cf)
);
#endif
if (cfa->e == 0 && cfa->f == 0 && cfa->g == 0 && cfa->h == 0)
- return INFINITY;
+ return C_INF;
else {
double
b11 = bound(cfa->a, cfa->e),
@@ -105,7 +105,7 @@ next_arith(CF cf)
float
bound(int n, int d)
{
- return d == 0 ? INFINITY : (float)n/(float)d;
+ return d == 0 ? C_INF : (float)n/(float)d;
}
void
@@ -134,7 +134,7 @@ ingest_x(CFA cf)
int p;
p = next(cf->x);
- if (p == INFINITY) {
+ if (p == C_INF) {
#ifdef DEBUG_IO
fprintf(stderr, "Ingested oo from x\n");
#endif
@@ -169,7 +169,7 @@ ingest_y(CFA cf)
int p;
p = next(cf->y);
- if (p == INFINITY) {
+ if (p == C_INF) {
#ifdef DEBUG_IO
fprintf(stderr, "Ingested oo from y\n");
#endif
View
2 cf_float.c
@@ -30,7 +30,7 @@ next_float(CF cf)
{
int p;
- if (cff->DONE) return INFINITY;
+ if (cff->DONE) return C_INF;
p = (int)cff->d;
#if 0
View
6 cf_holo.c
@@ -61,7 +61,7 @@ next_holo(CF cf)
fprintf(stderr, "I'm now %d %d / %d %d\n", cfh->a, cfh->b, cfh->c, cfh->d);
#endif
if (cfh->c == 0 && cfh->d == 0)
- return INFINITY;
+ return C_INF;
else {
float ub = bound(cfh->a, cfh->c), lb = bound(cfh->b, cfh->d);
if ((int)ub == (int)lb) {
@@ -82,7 +82,7 @@ next_holo(CF cf)
float
bound(int n, int d)
{
- return d == 0 ? INFINITY : (float)n/(float)d;
+ return d == 0 ? C_INF : (float)n/(float)d;
}
static void
@@ -116,7 +116,7 @@ ingest(CFH cf)
if (cf->x_done) return; /* err? */
p = next(cf->x);
- if (p == INFINITY) {
+ if (p == C_INF) {
#ifdef DEBUG
fprintf(stderr, "Ingested oo\n");
#endif
View
2 cf_rat.c
@@ -46,7 +46,7 @@ next_rat(CF cf)
{
int p, den = cfr->d;
- if (den == 0) return INFINITY;
+ if (den == 0) return C_INF;
p = cfr->n / den; /* integer division */
cfr->d = cfr->n - p * den;
View
12 libcf.3
@@ -231,27 +231,27 @@ Here's the implementation:
int
next_trunc(CF cf)
{
- if (cft->x_done) return INFINITY;
- else if (cft->n == 0) return INFINITY;
+ if (cft->x_done) return C_INF;
+ else if (cft->n == 0) return C_INF;
else {
int p = next(cft->x);
- if (p == INFINITY) cft->x_done = 1;
+ if (p == C_INF) cft->x_done = 1;
cft->n -= 1;
return P;
}
}
The only new machinery here is in next_trunc(). A CF can indicate
-that it has no more terms by returning the special constant INFINITY,
+that it has no more terms by returning the special constant C_INF,
defined in cf.h. Our CF_TRUNC object will do this if its counter
indicates that it has already delivered the appropriate number of
terms (cft->n == 0). It also contains a flag, x_done, that records
-whether its input CF has been exhausted; it returns INFINITY to
+whether its input CF has been exhausted; it returns C_INF to
indicate exhaustion in this case as well.
If the input is not already known to be exhausted, next_trunc() uses
the next() function provided by cf.h to read the next term from the
-input CF. If this next term is INFINITY, indicating that no more data
+input CF. If this next term is C_INF, indicating that no more data
is available, it sets the x_done flag; it then decrements its counter
and returns the term.

0 comments on commit 7a0b907

Please sign in to comment.