Re:Parsing can become accidentally quadratic because of sscanf
by orf on Monday March 01, 2021 @02:27PM
(#26307080)
How would the compiler be able to use any fast, floating point specific instructions if you parsed it as a hexadecimal string?
[ Parent
| on HN ]
Re:Parsing can become accidentally quadratic because of sscanf
by MauranKilom on Monday March 01, 2021 @03:33PM
(#26308012)
Not sure I understand the question. The suggestion is to use hexfloats, as they are unambiguous and straightforward to convert from and to (as opposed to anything with decimal significands): https://www.cplusplus.com/reference/ios/hexfloat/
Re:Parsing can become accidentally quadratic because of sscanf
by firebacon on Monday March 01, 2021 @03:43PM
(#26308124)
You don't need any specific instructions. The hex encoded double contains the final binary representation of the floating point number. So no conversion is required to load it, except maybe for swapping around bytes on some architectures. Conceptually:
double v;
memcpy(&v, "\x00\x00\x00\x00\x00\xe4\x94\x40", sizeof(v)); // LE