in reply to "force string context"?

There are a couple of cases where one can lose precision. If the user id is greater than 2**31 (signed integer on a 32 bit system), perl converts to floating point and precision may be lost.

The other possibility is that the user id is of the form a.b with b a long string of digits. This will be interpreted as a floating point number and depending on the precision, those extra digits will be rounded to fit into the floating point format.

If there are no decimal digits, I don't see how you can get into trouble with rounding operations in the string. To say more, we'd need to see examples of the user id.

-Mark

Replies are listed 'Best First'.
Re: Re: "force string context"?
by bronto (Priest) on Apr 16, 2004 at 09:06 UTC

    I got an example, and it seems that you got the point here. $user_id values are microtime timestamps, like 1082021975087815. And it is far bigger than 2**31:

    bronto@brabham:~$ perl -e 'print log(1082021975087815)/log(2),"\n"' 49.942651222871

    We are in the order of 2**50, so we really are in the field where rounding errors can occur.

    Thanks a lot for your help!

    Ciao!
    --bronto


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz