12345678910111213141516171819202122232425262728293031typet=Int64.tletof_strings=tryifString.starts_with~prefix:"0x"sthenInt64.of_stringselseInt64.of_string("0u"^s)withFailure_ase->Printf.eprintf"Unsigned int overflow: %s\n%!"s;raisee(* Avoid [Printf.sprintf "%Lu"], whose [camlinternalFormat] interpreter is a
heavy per-call allocation on this output-rendering path. A non-negative
[Int64] already reads as its unsigned self via the lightweight [Int64.to_string]
primitive; only a top-bit-set value (unsigned >= 2^63, rare) needs the format
interpreter. *)letto_strings=ifInt64.compares0L>=0thenInt64.to_stringselsePrintf.sprintf"%Lu"sletof_inti=Int64.of_inti(* Every caller must first bound the value so it is known to fit an OCaml [int]
(see [.mli]): an unguarded call that overflows is a bug at the call site, not
a condition to recover from here. *)letto_inti=matchInt64.unsigned_to_intiwithSomei->i|None->assertfalseletto_int64i=iletof_int64i=iletzero=0Lletone=1Lletcompare=Int64.unsigned_compare