Length of int in OCaml?

What is the length of int in OCaml? It is said that int in OCaml is 31. But I get this:

# (1 lsl 33);;
- : int = 8589934592

8589934592 is larger than 2^31.

asked Apr 10, 2013 by anonymous

1 Answer

 
Best answer

On my laptop (64-bit Fedora Linux), the int in OCaml is 63 bits. The code (count1s counts the number of bit 1s in an integer):

let rec count1s x =
    match (x lsr 1, x land 1) with
    | 0, n -> n
    | y, n -> n + count1s y

count1s (-1);;
answered Apr 10, 2013 by anonymous
edited Nov 23, 2013

Please log in or register to answer this question.

Related questions

1 answer
asked Aug 11, 2013 by anonymous
1 answer
1 answer
asked Dec 14, 2013 by anonymous
1 answer
1 answer
asked Aug 11, 2013 by anonymous
1 answer
asked Mar 11, 2013 by anonymous
Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...