Conversions between various integer types
val int_to_int32 : int ‑> int32 optionOcaml has the following integer types, with the following bit widths on 32-bit and 64-bit architectures.
arch arch
type 32b 64b
----------------------
int 31 63 (32 when compiled to JavaScript)
nativeint 32 64
int32 32 32
int64 64 64In both cases, the following inequalities hold:
width(int) < width(nativeint)
&& width(int32) <= width(nativeint) <= width(int64)The conversion functions come in one of two flavors.
If width(foo) <= width(bar) on both 32-bit and 64-bit architectures, then we have
val foo_to_bar : foo -> barotherwise we have
val foo_to_bar : foo -> bar option
val foo_to_bar_exn : foo -> barmodule Make_hex : functor (I : sig ... end) -> Base__.Int_intf.Hexable with type t := I.tin the output, to_string, of_string, sexp_of_t, and t_of_sexp convert
between t and signed hexadecimal with an optional "0x" or "0X" prefix.
val sexp_of_int_style : [ `No_underscores | `Underscores ] Base__.Import.refglobal ref affecting whether the sexp_of_t returned by Make
is consistent with the to_string input or the to_string_hum output
val insert_delimiter_every : string ‑> delimiter:char ‑> chars_per_delimiter:int ‑> stringutility for defining to_string_hum on numeric types -- takes a string matching
(-|+)?0-9a-fA-F+ and puts delimiter every chars_per_delimiter characters
starting from the right.