OCaml的最大Int值

Fee*_*Man 7 int primitive ocaml

我刚刚接受采访,我需要将这个值用于我想出的算法.在采访之后,我很好奇是否真的有办法获得最大的Int值.

我知道Int32.max_int和Int64.max_int.

但是,当我将Int32.max_int的值设置为int时,它超过了Int所具有的最大值.

# Int32.max_int;;
- : int32 = 2147483647l
# let a: int = 21474836471;;
Characters 13-24:
  let a: int = 21474836471;;
               ^^^^^^^^^^^
Error: Integer literal exceeds the range of representable integers of type int
Run Code Online (Sandbox Code Playgroud)

Jef*_*eld 11

$ ocaml
        OCaml version 4.01.0

# max_int;;
- : int = 4611686018427387903
# let a : int = max_int;;
val a : int = 4611686018427387903
Run Code Online (Sandbox Code Playgroud)

更新

对于它的价值,如果你在32位系统上,Int32.max_int仍然不适合int,即使你纠正了认为末尾的L(l)是1的错误:

# Int32.max_int;;
- : int32 = 2147483647l
# let i : int = 21474836471 (* Mistake *);;
Characters 14-25:
  let i : int = 21474836471 (* Mistake *);;
                ^^^^^^^^^^^
Error: Integer literal exceeds the range of representable integers of type int
# let i : int = 2147483647 (* No mistake *);;
Characters 14-24:
  let i : int = 2147483647 (* No mistake *);;
                ^^^^^^^^^^
Error: Integer literal exceeds the range of representable integers of type int
# 
Run Code Online (Sandbox Code Playgroud)

所以我会说L不是问题.