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

Wow thanks for all the replies ;) You have all been very patient. This is my first post here.

I have made some progress using "bigint" and have the code actually getting exact on digits of up to 19 characters. I found that the calculations are identical until the number reaches 19 digits. The c++ is using 64bit signed ints that it says "wrap around" on overflow with arithmitic operations. So at the end of a calculation you can have a -6213077893701800743 number. Perl's would still be a +positive number therefore they do not match.

Perl seems to keep adding straight on up so I have to reconcile that somehow after 19 digits. Sheesh how did I get here? Fun fun fun ;)

Replies are listed 'Best First'.
Re^3: The 16 digit number dilemma.
by GrandFather (Saint) on Feb 06, 2006 at 19:54 UTC

    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
      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
          A reply falls below the community's threshold of quality. You may see it by logging in.