C99 style hexadecimal floating point constants in OCaml

In OCaml, how can I parse C99-style floating point constants (either as literals or within strings) in hexadecimal form, for example 0x1.b000000000000p4

?

It looks like 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 converter Scanf

to parse them (like a C99 converter analog %a

to printf

).

+3


source to share


1 answer


float_of_string

should be able to parse them:

# float_of_string "0x1.199999999999Ap1";;
- : float = 2.2

      



However, as Alain Frisch pointed out in the OCaml bug tracker, actual support depends on the underlying libc and will not work on MSVC ports at this time.

+6


source







All Articles