Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 48 lines (35 sloc) 0.651 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47


#include "cf_float.h"
#include <math.h>
#define EPSILON 1e-10


typedef struct st_cf_float {
  BASE_CF;
  double d;
} *CFF;

#define cff ((CFF)cf)

static int next_float(CF);

CF
new_float(double d)
{
  CFF cf = (CFF) new_cf(sizeof(struct st_cf_float));
  if (cf == 0) return 0;
  cf->d = d;
  cf->DONE = 0;
  cf->next = next_float;
  return (CF)cf;
}

static int
next_float(CF cf)
{
  int p;

  if (cff->DONE) return C_INF;

  p = (int)cff->d;
#if 0
printf("\n p=%d d=%lf diff=%.20f\n",
p, cff->d, fabs(p - cff->d));
#endif
  if (fabs(p - cff->d) <= EPSILON)
    cff->DONE = 1;
  else
    cff->d = 1/(cff->d - p);
  
  return p;
}

Something went wrong with that request. Please try again.