This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Guile inexact math bug?


hjstein@bfr.co.il (Harvey J. Stein) writes:

> Isn't this a guile math bug:
> 
>    hjstein@blinky:~$ guile
>    guile> (log10 1000)
>    3.0
>    guile> (truncate (log10 1000))
>    2.0
>    guile> (truncate 3.0)
>    3.0
> 
> If it's going to display (log10 1000) as 3.0, then it has to truncate
> to 3.0.  If it's not really 3.0, then it shouldn't display that way.

The problem is that it's displaying with limited precision (and worse,
there doesn't appear to be any way to change the precision
currently). The offender is idbl2str. The problem isn't limited to
guile, though:

void
test_main(void)
{
  double a, b;
  a = log10(1000.0);
/*This is what guile does for log10*/
  b = log(1000.0)/log(10);
  printf("%f\n", a);
  printf("%f\n", b);
  printf("%f\n", floor(a));
  printf("%f\n", floor(b));
}

Will give:
3.000000
3.000000
3.000000
2.000000

while:

void
test_main(void)
{
  double a, b;
  a = log10(1000.0);
  b = log(1000.0)/log(10);
  printf("%#.20f\n", a);
  printf("%#.20f\n", b);
  printf("%#.20f\n", floor(a));
  printf("%#.20f\n", floor(b));
}

gives:
3.00000000000000000000
2.99999999999999955591
3.00000000000000000000
2.00000000000000000000

I think the the best solution to this is to make idbl2str use sprintf,
and add a variable that can be set from scheme for the printing
precision to use.

-- 
Greg