in reply to Re^4: &1 is no faster than %2 when checking for oddness. Oh well.
in thread &1 is no faster than %2 when checking for oddness. Oh well.

BrowserUk,
I used Math::BigInt without testing if it is necessary because 2 ** 60 + 2 ** 30 seemed big.

The point of my post was that if you know you are summing 1 .. N then don't - use the formula. Programmer knowledge of the specific problem beats a generalization.

Cheers - L~R

  • Comment on Re^5: &1 is no faster than %2 when checking for oddness. Oh well.

Replies are listed 'Best First'.
Re^6: &1 is no faster than %2 when checking for oddness. Oh well.
by BrowserUk (Patriarch) on Nov 16, 2006 at 20:21 UTC
    f you know you are summing 1 .. N then don't - use the formula.

    See above. Tanktalus used the example of sum 1 .. a big number; I simply continued with his example.

    The example is simply a placeholder for any operation that could lead to the accumulation of a number larger than a 32-bit integer can hold. Another example might be

    sum @array;

    where the numbers in the array total to more than 2**32, but for which there is no way to predict a formula to substitute for the accumulation.

    Ie. Out of context, your point is well taken. In context, it is irrelavent, as it demonstrates the limitations of the chosen example, not the point that was being made.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.