I think some change will have to be made to the XS code: for example, (a) make it output the newlines itself (directly where it outputs the numbers)

That does fix the problem - ie in MPFR.xs replace
SV * Rmpfr_out_str(SV * p, SV * base, SV * dig, SV * round) { if(SvIV(base) < 2 || SvIV(base) > 36) croak("2nd argument supplie +d to Rmpfr_out_str is out of allowable range (must be between 2 and 3 +6 inclusive)"); return newSVuv(mpfr_out_str(NULL, SvUV(base), SvUV(dig), *(INT2PT +R(mpfr_t *, SvIV(SvRV(p)))), SvUV(round))); }
with
SV * Rmpfr_out_str(SV * p, SV * base, SV * dig, SV * round) { unsigned long ret; if(SvIV(base) < 2 || SvIV(base) > 36) croak("2nd argument supplie +d to Rmpfr_out_str is out of allowable range (must be between 2 and 3 +6 inclusive)"); ret = mpfr_out_str(NULL, SvUV(base), SvUV(dig), *(INT2PTR(mpfr_t +*, SvIV(SvRV(p)))), SvUV(round)); printf("\n"); return newSVuv(ret); }
On reflection, it probably doesn't make a lot of sense to be wrapping mpfr_out_str. I'll probably just leave Rmpfr_out_str as it is, and document the fact that calling it in a loop can lead to garbled output (and point out that it's safer to use Rmpfr_get_str).

I mentioned elsewhere in this thread that Rmpfr_get_str currently can sometimes output one less digit than it ought (due to programmer error). The fix for that is to replace, in MPFR.xs (in the Rmpfr_deref2 function)
mpfr_get_str(out, expptr, b, n_dig, *(INT2PTR(mpfr_t *, SvIV(SvRV(p))) +), SvUV(round));
with
mpfr_get_str(out, expptr, b, SvUV(n_digits), *(INT2PTR(mpfr_t *, SvIV( +SvRV(p)))), SvUV(round));
That fix will find its way into the next version of Math::MPFR.

Cheers,
Rob

In reply to Re^2: xs outputs faster than perl can keep up by syphilis
in thread xs outputs faster than perl can keep up by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.