[Gretl-devel] Small bug in seasonal dummies

Allin Cottrell cottrell at wfu.edu
Tue Oct 2 13:37:38 EDT 2007


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

>      } 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, d = ceil(log10(pdinfo->pd));
> +	for(i=0; i<d; i++) {
> +	    x *= 10;
>  	}
> +	ret = (int) x;

I agree it would be more elegant to avoid strings, but I'm afraid 
this works right only because (double) 10 = 9.9999999999909051.

We return a zero-based index (9 in this case).  What one would 
like to do is

  ret = (int) x - 1;

for exact x.  But it's going to screw up if x is not exact.

Allin.


More information about the Gretl-devel mailing list