Topic: floating point lit format - clarification sought
Author: Linda Sherman <linsherm@gte.net>
Date: 1999/11/25 Raw View
I'm looking for opinions on whether this is legal syntax for a floating
point literal:
09.0
09e-1
Borland's Builder 4 complains about the 9 being an "illegal octal
digit", but my reading of the standard says that any digit is allowed in
the first position. Also, Builder is obviously treating the fractional
part as decimal in the following example:
float x = 072.0;
std::printf( "%g", x ); // outputs "72"
I'm working on a C++ lexer and would like to make sure that my code is
handling this correctly.
TIA
Lin
--
Linda K Sherman <lindash@concentric.net>
linsherm@gte.net www.cti-pro.com www.dalati.com
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Steve Clamage <stephen.clamage@sun.com>
Date: 1999/11/25 Raw View
Linda Sherman wrote:
>
> I'm looking for opinions on whether this is legal syntax for a floating
> point literal:
>
> 09.0
> 09e-1
>
> Borland's Builder 4 complains about the 9 being an "illegal octal
> digit", but my reading of the standard says that any digit is allowed in
> the first position.
Yes. An integer literal that starts with a 0 is octal or hex, but
a floating literal can start with any digit -- 0 is not excluded.
Refer to section 2.13.3 in the standard.
On seeing a literal starting with 0<digit>, the compiler must scan
until a non-digit is seen before deciding whether it is an octal
integer literal or a floating literal.
--
Steve Clamage, stephen.clamage@sun.com
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]