I’ve got a hexadecimal floating-point constant which I’d like to declare directly in my C program, and avoid conversion. I believe it must be normalized first, right? How do I normalize it and declare it?
// hex constant 0xDE.488631
double val = 0xDE.488631; // Error must have exponent.
double val = 0x0.DE488631p-2; // Pretty sure this is wrong.
You can use an exponent of
0:Which in more normal looking notation means DE.488641×20 (in base 16, of course). Your guess was close – the exponent is a binary exponent, not a hex exponent, though. You’re also using a negative exponent when you want to have a positive exponent. Correcting your second example, you can use:
Which in regular mathematical notation means 0.DE488631×28, or equivalently with a hexadecimal base for the exponent, 0.DE488631×162.
I think using an exponent of
0is a lot easier to understand unless you have some reason to use the form from your second example.