[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
More on rounding....
It isn't just Perl on my machine:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main (argc, argv) {
double r;
char buf[32];
r = 25.25 * .06;
printf ("r %f rounds to %.2f\n", r, r);
gcvt(r, 8, buf);
printf ("gcvt says %s\n", buf);
exit(0);
}
It seems like it is a glibc bug, because I have found no mention
of rounding problems on the Perl porters group, and there are no
arbitrary-precision decimal math packages available to solve what
you would think would be a common need.
Thanks for the investigation and bug report; don't know what I can do
but now that I am aware of the problem I might think of something. Just
doing this
$r =~ s/(\d*\.\d+)/$1 . ( '0' x ( 16 - length($1) ) ) . 1/e;
might be practical, but I have learned to think about side effects before
making this kind of tweezy fix....
--
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
131 Willow Lane, Floor 2 | || _ \
It's a little-known fact Oxford, OH 45056 | || |_) |
that the Y1K problem caused <mikeh@minivend.com> |___| _ <
the Dark Ages. -- unknown 513.523.7621 FAX 7501 |_| \_\