in reply to The 16 digit number dilemma.

My first suggestion would be to try use bigint. I suspect -- and without the C++ code can't be sure -- that your problem relates to Perl usually doing all its arithmetic in floating point (unless a pragma, such as use bigint is used).

The other course may be to try to port the C++ to Linux.

emc

" When in doubt, use brute force." — Ken Thompson

Replies are listed 'Best First'.
Re^2: The 16 digit number dilemma.
by docster (Novice) on Feb 06, 2006 at 19:42 UTC
    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 ;)

      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 ;)