ocaml-stdint
ocaml-stdint copied to clipboard
of_string for unsigned integers does not raise exception on negative inputs
Actual behavior
Here is a toplevel session:
μ> #require "stdint";;
μ> "-1" |> Stdint.Uint128.of_string |> Stdint.Uint128.to_string;;
- : string = "340282366920938463463374607431768211455"
Basically, this is the maximum 128-bit unsigned integer. It behaves the same for the rest of bit widths.
Expected behavior
Raises an exception according to the description here:
https://github.com/andrenth/ocaml-stdint/blob/48f97cd7e577a432064f33e4c2ad6859826716ad/lib/stdint.mli#L292-L297:
Yes, that seems confusing. @rixed what do you think?
Given the quoted documentation and the fact that other Int modules seem to raise an exception (although not Failure but Invalid_arg, which looks better to me), I'd say that Uint128.of_string should indeed raise. I would favor if all of the of_string functions would raise the same exception BTW.