In OCaml, how can I parse C99-style floating-point constants (either as literals or inside strings) in hexadecimal, such as 0x1.b000000000000p4
?
It seems that they are not valid literals:
# let c = 0x1.b000000000000p4;;
Characters 12-27:
let c = 0x1.b000000000000p4;;
^^^^^^^^^^^^^^^
Error: Unbound record field b000000000000p4
And there seems to be no Scanf
converter to parse them (e.g. a counterpart to C99's %a
converter for printf
).
float_of_string
should be able to parse them:However as Alain Frisch noted on OCaml's bug tracker the support actually depends on the underlying libc and won't currently work on the MSVC ports.