Subject: | Win32, buffering problem with Rmpfr_out_str |
## Bug Demo Script ##
use warnings;
use Math::MPFR qw (:mpfr);
die "**USAGE: perl script.pl prec **" unless @ARGV;
Rmpfr_set_default_prec($ARGV[0]);
$string = '9' x 4096 . '8' x 5;
$mpfr = Math::MPFR->new($string);
Rmpfr_out_str($mpfr, 10, 0, GMP_RNDN);
__END__
Perl 5.8.8, mpfr-2.3.0, gmp-4.2.2 (but probably applies to earlier
versions of all three).
Affects Win32 only (I think).
For precisions less than 204096, the outptut is as expected.
But for precisions greater than or equal to 204096, the mantissa is
truncated to the first 4098 characters (4099 characters if $mpfr is
negative).
That is, each fputc() in mpfr_out_str() functions correctly, but the
fputs() only releases the next 4096 characters - which, I suspect, is
all that the buffer holds.
For example, if precision is set to 204095, Rmpfr_out_str() returns
61446, and the following *61446-character* string is output:
9.99....998888800.....00e4100
That is as it should be.
But if precision is set to 204096, Rmpfr_out_str() returns 61447, and
the following *4103-character* string is output:
9.99....998e4100
Even if I change the 3rd arg from "0" to "61441", the output doesn't
alter.
I can't find a fix for the problem (from within either perl, XS or the
mpfr source).
Annoyingly, I also can't reproduce the problem outside of mpfr.
Programs written in C aren't affected - the behaviour relates only to
Math::MPFR.
In short, I don't know why it happens, and I've filed this bug report
in the hopes that someone might stumble across it and provide/suggest a
solution.
Cheers,
Rob