[Gretl-devel] Small bug in seasonal dummies

Riccardo (Jack) Lucchetti r.lucchetti at univpm.it
Tue Oct 2 13:10:36 EDT 2007


On Tue, 2 Oct 2007, Riccardo (Jack) Lucchetti wrote:

> Confirmed. The trouble is that the string "10" ends with the character "0". 
> If I'm not mistaken, the following patch should fix it. Basically, it avoids 
> conversion to strings. Allin, I ran just a limited series of tests, so I'm 
> not committing it myself. Could you take a look?

Doh. I didn't know C had a "log10" builtin function. This one's better.

Index: lib/src/dataio.c
===================================================================
RCS file: /cvsroot/gretl/gretl/lib/src/dataio.c,v
retrieving revision 1.328
diff -u -w -u -r1.328 dataio.c
--- lib/src/dataio.c	2 Oct 2007 17:04:10 -0000	1.328
+++ lib/src/dataio.c	2 Oct 2007 17:09:04 -0000
@@ -912,19 +912,14 @@
  	ret = t % pdinfo->pd;
      } else {
  	/* quarterly, monthly, hourly... */
-	double x = date(t, pdinfo->pd, pdinfo->sd0);
-	int d = ceil(log10(pdinfo->pd));
-	char *p, s[32];

-	sprintf(s, "%.*f", d, x);
-	p = strchr(s, '.');
-	if (p == NULL) {
-	    p = strchr(s, ',');
-	}
-	if (p != NULL) {
-	    sscanf(p + 1, "%d", &ret);
-	    ret -= 1;
+	double x = date(t, pdinfo->pd, pdinfo->sd0);
+	x -= floor(x);
+	int i, scale = (int) (1 + log10(pdinfo->pd));
+	for(i=0; i<scale; i++) {
+	    x *= 10;
  	}
+	ret = (int) x;
      }

      return ret;

Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche

r.lucchetti at univpm.it
http://www.econ.univpm.it/lucchetti


More information about the Gretl-devel mailing list