in reply to Re^2: The 16 digit number dilemma.
in thread The 16 digit number dilemma.

Mask your result with a bitwise and: $result &= 0xffffffffffffffff;. You may need to do this after each operation or just at the end - depends what you are doing.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^4: The 16 digit number dilemma.
by docster (Novice) on Feb 06, 2006 at 20:11 UTC
    Not sure I follow you. I have it boiled down to I need to do this and I will have it:

    Number : 12233666185912650873

    Forward Cap: 9223372036854775807

    Reverse Cap: -9223372036854775808

    Perl Sees : 12233666185912650873

    Windows Sees: -6213077893701800743

    The windows app counts UP to the forward cap and then starts counting backwards down the reverse cap. Perl counts straight on up.

    Somehow I need to mimic that in perl, count to Forward cap and then reverse. Or take the end result and do some math on it. I welcome any help, I really have no idea what I am doing here ;)

      It's the same number. Windows is showing it as a 64 bit signed value and Perl is showing it unsigned or using a larger representation. You can convert to the Windows value by $ans = -(0x10000000000000000 - $ans) if 0x8000000000000000 & $ans;.


      DWIM is Perl's answer to Gödel
        I would think that would do the trick but it is off a little:
        Test win: -6213077893701800743 Test perl: -6213077893701849127
        I think I need to convert to the 64 before doing the calculations. The numbers do not seem the same after calculating them in different formats. The turning point is after the 64 cap of 9223372..... They stay identical until then. Is there a way to do that?

        I have i (my integer) declared as:

        my $i = Math::BigInt->new('0');
        Is it possible to make it a signed 64 or whatever windows there is using to begin with? Thank ya so much! Im very close. Bah: I think I see the problem here with warnings:
        $z = -(0x10000000000000000 - $i) if 0x8000000000000000 & $i; # line 115 Integer overflow in hexadecimal number at ./testgen line 115 (#1) (W o +verflow) The hexadecimal, octal or binary number you have specified e +ither as a literal or as an argument to hex() or oct() is too big for + your architecture, and has been converted to a floating point number +. On a 32-bit architecture the largest hexadecimal, octal or binary n +umber representable without overflow is 0xFFFFFFFF, 037777777777, or +0b11111111111111111111111111111111 respectively. Note that Perl tran +sparently promotes all numbers to a floating point representation in +ternally--subject to loss of precision errors in subsequent operation +s.
        I am running an athalon XP with gentoo linux, 2.6 kernel. Is it possible to run 64 bit integers with it? The c++ code was written on windows 2000, I would have certainly thought linux was at least equal ;)
        A reply falls below the community's threshold of quality. You may see it by logging in.