This is the grammar of hexadecimal floating point constant, as defined in C99 draft, written as regular expression:
0[xX]([a-fA-F0-9]*[.][a-fA-F0-9]+|[a-fA-F0-9]+[.]?)[pP][+-]?[0-9]+[flFL]?
Which consists of 4 parts:
0[xX]
: Hexadecimal prefix, either of these 2:
0x
0X
([a-fA-F0-9]*[.][a-fA-F0-9]+|[a-fA-F0-9]+[.]?)
: Hexadecimal fractional constant, for example:
34.2f
.de
b3.
or hexadecimal digit sequence (whole number in hexadecimal), for example:
2f4
10
The second part basically describes the mantissa.
[pP][+-]?[0-9]+
: Binary exponent part (specified in decimal), for example:
p-4
p20
We specify a hexadecimal floating point constant by specifying the mantissa in hexadecimal, and the exponent b (for base 2) in decimal.
[flFL]?
: Optional floating suffix, to indicate the type (float
, double
or long double
).