How do I parse a string with a C++ style hex float (%a) to a f64?

Viewed 119

I need to parse a text file with bunch of float numbers that were created via C++'s printf("%a") and looks like:

-0x1.68p+6 -0x1.68p+7

As I understand it, this is the mantissa and exponent in hex.

Is there any way to parse this with the standard library? I could not find a f64::from_str_radix, and even if it existed, would it parse the 0x and p parts correctly?

I suppose I missed something, because the lossless conversion of f64 <-> String should be popular enough functions to include them into standard library.

0 Answers
Related