I just came off an interview where I needed to use this value for the algorithm I came up with. After the interview I was curious if there was actually a way to get the max Int value.
I am aware of Int32.max_int and Int64.max_int.
However when I set Int32.max_int's value to an int it exceeded the max value an Int have have.
# 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
Value of INT_MAX is +2147483647. Value of INT_MIN is -2147483648.
unit — The Unit Value The built-in printing functions return type unit, for example; the value of a while or for loop (both of which are expressions, not "statements") is also of type unit. OCaml uses this convention to help catch more type errors.
$ ocaml
OCaml version 4.01.0
# max_int;;
- : int = 4611686018427387903
# let a : int = max_int;;
val a : int = 4611686018427387903
Update
For what it's worth, if you're on a 32-bit system, Int32.max_int still doesn't fit into an int, even if you correct the mistake of thinking that the L (l) at the end is a 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
#
So I'd say the L wasn't the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With