in reply to Range iterator outside integer range ... Why?

$ perl -e "print int ((1<<63)-512)" 9223372036854775296 $ perl -e "print int ((2**63)-512)" 9223372036854775808

Replies are listed 'Best First'.
Re^2: Range iterator outside integer range ... Why?
by BrowserUk (Patriarch) on Jan 16, 2015 at 16:17 UTC

    So, if I'm interpreting your (rather terse) message correctly, because 2**63 is greater than a signed 64-bit int, it gets coersed into a double; before the subtraction is done.

    And because 63-bits of precision is greater than the 53 bits the double can retain, by the time the subtraction is done, the loss of precision causes the problem.

    In anycase, 1<<63-1 is a much nicer way of writing that constant. Thanks!


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      Or, as stated by oiskuu here, it's because 2**63 is implemented with pow, when 1<<63 actually works on integers.