in reply to Re^2: Overloading print()
in thread Overloading print()

"Wouldn't it be nice if print was overloaded to use mpfr_out_str" ... But then, that would mean that every time someone did $x = "$blessed_obj"; the value encapsulated in $blessed_obj is going to be printed to stdout

mpfr_get_str() probably does what you want here. If so, I'd wager that Math::MPFR already does what you want, since it exposes Rmpfr_get_str() and, using it, already overloads its objects' stringification.

-pilcrow

Replies are listed 'Best First'.
Re^4: Overloading print()
by syphilis (Archbishop) on Sep 06, 2007 at 05:52 UTC
    mpfr_get_str() probably does what you want here

    Unfortunately it doesn't. All it does is return a string of digits (with a leading minus sign if it's a negative number) for the mantissa, and sets a variable to the value of the exponent. It's then up to Rmpfr_get_str to put the number into scientific notation, based on the information provided by mpfr_get_str.

    If, as one would instinctively expect, mpfr_get_str returned a string formatted in the same way as the mpfr_out_str output, then you would be absolutely correct ... and this whole thread would never bave been born :-)

    Cheers,
    Rob