Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocaml 4.01.0 lsr function in OCaml only uses bottom 7 bits of shift value #6299

Closed
vicuna opened this issue Jan 20, 2014 · 2 comments
Closed

Comments

@vicuna
Copy link

vicuna commented Jan 20, 2014

Original bug ID: 6299
Reporter: jrrk100
Status: closed (set by @xavierleroy on 2015-12-11T18:26:44Z)
Resolution: not a bug
Priority: normal
Severity: major
Platform: amd64
OS: OSX
OS Version: 10.9.1
Category: runtime system and C interface

Bug description

When using x lsr y where y is a large number (> 63), the answer should always be zero, however if y reaches 128 the actual shift goes back to zero.

Steps to reproduce

$ ocaml
OCaml version 4.01.0

1024 lsr 9;;

  • : int = 2

1 lsr 128;;

  • : int = 1
@vicuna
Copy link
Author

vicuna commented Jan 20, 2014

Comment author: @dbuenzli

The result is unspecified if y > platform width (see the docs) .

@vicuna
Copy link
Author

vicuna commented May 3, 2014

Comment author: @xavierleroy

This is documented clearly in the users's manual.

"n lsr m shifts n to the right by m bits. This is a logical shift: zeroes are inserted regardless of the sign of n. The result is unspecified if m < 0 or m >= bitsize."

Note that different processors behave differently if m < 0 or m >= bitsize. For example, x86-64 takes m modulo 64, but ARM-32 takes m modul0 256.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant