[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] Bug in pic? And how to do this right?
From: |
Ralph Corderoy |
Subject: |
Re: [Groff] Bug in pic? And how to do this right? |
Date: |
Fri, 12 Dec 2003 19:14:37 +0000 |
Hi Ted,
> This seems to be a bug in grops.
> ...
> Groff version 1.16.1:
>
> 288 -322.656 720.002 101.5369 78.4631 DA
> ...
> Now, from the correct values: 101.5369 78.4631
>
> we can get the groff 1.18.1 values: 102 78.5 by rounding to 3
> significant figures. Maybe this is what recent versions of grops do
Thanks for all the hard work.
$ cvs diff -r groff-1_16_1 -r groff-1_18_1 grops
...
--- grops/ps.cc 18 Jun 2000 10:13:56 -0000 1.4
+++ grops/ps.cc 20 Jun 2002 05:58:36 -0000 1.20
...
@@ -310,7 +321,7 @@
ps_output &ps_output::put_float(double d)
{
char buf[128];
- sprintf(buf, "%.4f", d);
+ sprintf(buf, "%.3g", d);
int len = strlen(buf);
if (col > 0 && col + len + need_space > max_line_length) {
putc('\n', fp);
@@ -345,6 +356,26 @@
return *this;
}
Version 1.13 of that file has the above change, so the CVS tags suggest
groff 1.18 was the first release with the bug.
groff-1_18: 1.20
groff-1_17_2: 1.12
The comment for the change includes
revision 1.13
...
* src/devices/grops/ps.cc (ps_output::put_float): Use `%g' to have
trailing zeroes removed.
But as you say switching from %.4f to %.3g has problems.
$ awk \
> 'BEGIN{for (a=.0006;a<70000;a*=10){b=a+1234;printf"%.4f %.3g\n",b,b}}' \
> </dev/null
1234.0006 1.23e+03
1234.0060 1.23e+03
1234.0600 1.23e+03
1234.6000 1.23e+03
1240.0000 1.24e+03
1294.0000 1.29e+03
1834.0000 1.83e+03
7234.0000 7.23e+03
61234.0000 6.12e+04
If trailing zeroes particuarly add bloat then a
s/0+$//
s/\.$//
to the output of %.4f might be worthwhile.
Cheers,
Ralph.