in reply to Re^5: converting large hex values
in thread converting large hex values

..thanks - however, I put the "use bignum => 50" line of code before the "print hex("0xbe91cfb586466d02"),"\n";" statement and it still didn't give me the precision that the -Mbignum=a,50 gave me - I must be missing something - does the "print hex" have to be somehow part of the "use bignum" option? ..again, thanks for any insights...

Replies are listed 'Best First'.
Re^7: converting large hex values
by ikegami (Patriarch) on Jul 30, 2009 at 16:10 UTC

    I must be missing something

    Yes, cause they're equivalent. What makes you think it works with -Mbignum=a,50? (I was wonder wondering why you'd need to specify the accuracy in the first place since I thought it defaulted to infinite accuracy.)

    $ perl -Mbignum=a,50 -wle'print hex("0xbe91cfb586466d02")' Integer overflow in hexadecimal number at -e line 1. Hexadecimal number > 0xffffffff non-portable at -e line 1. 1.37319851173781e+19

    bigint doesn't affect strings, so it never comes into play in the above. Even if it did, hex is not something that can be overloaded, so it would fail anyway even if the string was converted into a BigInt.

    $ perl -MMath::BigInt -wle'print hex(Math::BigInt->new("0xbe91cfb58646 +6d02"))' Integer overflow in hexadecimal number at -e line 1. Hexadecimal number > 0xffffffff non-portable at -e line 1. 9.18481776382103e+22

    If you use the string as the second operand of something whose first operand is a Math::BigInt, it'll work.

    $ perl -Mbigint -wle'print 0+"0xbe91cfb586466d02"' 13731985117378145538
    The above is short for
    $ perl -MMath::BigInt -wle'print Math::BigInt->new(0)+"0xbe91cfb586466 +d02"' 13731985117378145538
    which implicitly does
    $ perl -MMath::BigInt -wle'print Math::BigInt->new(0)->badd(Math::BigI +nt->new("0xbe91cfb586466d02"))' 13731985117378145538
    so you could also use
    $ perl -MMath::BigInt -wle'print Math::BigInt->new("0xbe91cfb586466d02 +")' 13731985117378145538
      Thanks! ..I'm really going to have to mull over all the info - Perl syntax is "killing" me - I came from mainframes, FORTRAN, ASSEMBLER, etc... What I did do was include the following in my source code: use bignum; print MATH::BIGINT->new("0xbe91cfb586466d02"); Now, interestingly enough, the following printed out: 1373198511737814553812 - ..where did the final '12' come from? ..was it the semicolon? ..and how do I get rid of it? Again, thanks for your help (& patience)...spooky

        I came from mainframes, FORTRAN, ASSEMBLER, etc...

        Then you should understand the problems of trying to fit a 64-bit value in a 32-bit integer or 53-bit precision float.

        I did do was include the following in my source code: use bignum; print MATH::BIGINT->new("0xbe91cfb586466d02"); Now, interestingly enough, the following printed out: 1373198511737814553812

        The module is Math::BigInt. That doesn't run.

        This is the second time you've told us you got A from B when you didn't.

        Now, interestingly enough, the following printed out: 1373198511737814553812 - ..where did the final '12' come from? ..was it the semicolon?

        What semicolon? 0x12 is the code point for newline in ASCII-based character sets. Seems the code you showed us is not even close to what you used.

Re^7: converting large hex values
by Spooky (Beadle) on Jul 30, 2009 at 15:58 UTC
    ooops - I meant to say "use bignum a=> 50" which is what I actually coded...