ISO/IEC JTC1 SC22 WG21 P00245r0
To: EWG, CWGThomas Köppe <firstname.lastname@example.org>
There is a base-2 scientific notation for floating point values:
The significand is given in hexadecimal, and the exponent is given in decimal and interpreted
with respect to base 2. This notation is convenient for certain uses. For example, the smallest
normal IEEE-754 single precision value is readily written as
generally, this notation can be used when an exact object representation is desired (and the
floating point implementation uses a base-2 or base-2n representation).
The standard library outputs this representation via the
for ostreams, and via the
A conversion specifiers in
formatted input works because
strtod recognises this representation (and
the semantics of formatted istream input operations and
scanf are defined in
strtod, but see below for a detail). We should also allow this
representation as a literal in the core language.
Note that the C language which is referenced by the C++ standard also allows this literal syntax.
This is a core language extension that adds a new numeric literal syntax. The proposed
syntax is ill-formed in the current working draft. Note that non-standard user-defined
literals must start with an underscore, and the standard library does not define a UDL
In section [lex.fcon] (2.13.4 in the working draft), change the grammar as follows (cf. C11 18.104.22.168/1).
Esignopt digit-sequence sign: one of
+ -digit-sequence: digit digit-sequence 'opt digit floating-suffix: one of
f l F L
Change the subsequent paragraph 1 in the following way:
1.602176565e-19have the same value.] Either the integer part or the fraction part (not both) can be omitted
doubleunless explicitly specified by a suffix. The suffixes
float, the suffixes
long double. If the scaled value is not in the range of representable values for its type, the program is ill-formed.
Drafting note. We changed “significant” to “significand” and “decimal point” to “radix point”.
Also change the grammar in section [lex.ext] (2.13.8):
Although the library rules in [facet.num.get.members] say that formatted floating
point input uses the conversion rules of
strtod etc., the section also
restricts the set of characters permissible for floating point parsing to
"0123456789abcdefxABCDEFX+-", which is missing the values
P. Should the present proposal succeed, we plan to either create a new
library proposal, or revisit LWG issue 2381
to add support for parsing hexadecimal floating point literals to the standard library.
Hexadecimal float literals are already supported as a vendor extension by several compilers: Clang, EDG, Embarcadero, GCC. Formatted input via iostreams is supported by libc++.