Loading ...
Sorry, an error occurred while loading the content.

Overflow checking for integer lsl operation

Expand Messages
  • Raj Bandyopadhyay
    Hi all Is there a good way for checking overflow for the integer left-shift (lsl) operator in OCaml? Thanks Raj
    Message 1 of 2 , Jul 8, 2008
    • 0 Attachment
      Hi all

      Is there a good way for checking overflow for the integer left-shift
      (lsl) operator in OCaml?

      Thanks
      Raj
    • Eric Cooper
      ... A k-bit left shift (n lsl k) will overflow iff any of the upper k bits is 1, which you can check by shifting, masking, and comparing to 0. Your code will
      Message 2 of 2 , Jul 8, 2008
      • 0 Attachment
        On Tue, Jul 08, 2008 at 09:07:40AM -0500, Raj Bandyopadhyay wrote:
        > Is there a good way for checking overflow for the integer left-shift
        > (lsl) operator in OCaml?

        A k-bit left shift (n lsl k) will overflow iff any of the upper k
        bits is 1, which you can check by shifting, masking, and comparing to 0.
        Your code will depend on the word size, though.

        --
        Eric Cooper e c c @ c m u . e d u
      Your message has been successfully submitted and would be delivered to recipients shortly.