in reply to Re^3: Exasperated with 64-bit integer builds of perl
in thread Exasperated with 64-bit integer builds of perl

I have meanwhile thought of another way to get what you want: sprintf

I don't quite follow. At its simplest, what I want is to have a string like '1.44115188075868217e17' converted to the numeric value 144115188075868217 on a use64bitint build of perl that doesn't have long doubles. I can't see a way of doing that using (s)printf. I find that printf "%d", '1.44115188075868217e17' produces 144115188075868224. Sorry if I've missed the point. (I do that sometimes :-)

By looking at the sign, mantissa, and exponent it's not all that difficult to get the required result - and that's pretty much how I'll be doing it. Thanks Moron.

Cheers,
Rob

Replies are listed 'Best First'.
Re^5: Exasperated with 64-bit integer builds of perl
by Moron (Curate) on May 31, 2007 at 11:05 UTC
    I should have mentioned pack("Q", $string) first - but I can't recompile Perl in 64 bits here in the office to test it anyway :(
    __________________________________________________________________________________

    ^M Free your mind!

      I should have mentioned pack("Q", $string)

      Doesn't seem to DWIM:
      C:\_64>perl -e "$_=unpack('Q',pack('Q','1.44115188075868217e+017'));pr +int" 144115188075868224 C:\_64>
      I believe it just packs the NV into the quad.

      Cheers,
      Rob
        Hmmm, then that leaves me with one last suggestion: Math::BigFloat and Math::BigInt.
        __________________________________________________________________________________

        ^M Free your mind!