By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,910 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,910 IT Pros & Developers. It's quick & easy.

Definition of floating literal in C++ standard

P: n/a
Hi,

The definition of floating literal in the C++ (ISO/IEC 14882:2003)
grammar is as follows (Note: I have replaced the "opt" subscript used
in the standard with [ ] to indicate optional symbol).

------BEGIN------
floating-literal:
fractional-constant [exponent-part] [floating-suffix]
digit-sequence exponent-part [floating-suffix]
fractional-constant:
[digit-sequence] . digit-sequence
digit-sequence .
exponent-part:
e signopt digit-sequence
E signopt digit-sequence
sign: one of
+ -
digit-sequence:
digit
digit-sequence digit
floating-suffix: one of
f l F L
------END------

The above specification does not allow for an optional sign (+ or -)
to be specified for the fractional-constant (for eg. -2.1e+2). Is this
a defect in the standard or am I missing something?

Thanks,
Murali
Feb 2 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
That's correct -- a sequence like -2.1e+2 is a unary negation operator
followed by a floating point literal. The literal itself is never
negative.
Thank you for the clarity.

What's the motivation for this, rather than just allow for numeric
constants to be negative ?
Feb 3 '08 #2

P: n/a
On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
<dominic.con...@gmail.comwrote:
That's correct -- a sequence like -2.1e+2 is a unary
negation operator followed by a floating point literal. The
literal itself is never negative.
Thank you for the clarity.
What's the motivation for this, rather than just allow for
numeric constants to be negative ?
The effects allowing them to be negative would have elsewhere.
Given "a-42", for example, you really don't want it to resolve
to two tokens, the symbol "a" and the integral constant -42,
without an operator.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Feb 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.