Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Definition of floating literal in C++ standard

Reply
Thread Tools

Definition of floating literal in C++ standard

 
 
murali.desikan@gmail.com
Guest
Posts: n/a
 
      02-02-2008
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
 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      02-03-2008
In article <8b39194f-6996-4664-99c6-4e5e4dafb2a4
@l32g2000hse.googlegroups.com>, http://www.velocityreviews.com/forums/(E-Mail Removed) says...

[ ... ]

> 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?


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.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
 
Dominic Connor, Quant Headhunter
Guest
Posts: n/a
 
      02-03-2008
> 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 ?
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      02-03-2008
On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
<(E-Mail Removed)> wrote:
> > 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:(E-Mail Removed)
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
 
Reply With Quote
 
Andrew Koenig
Guest
Posts: n/a
 
      02-04-2008
"James Kanze" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
<(E-Mail Removed)> wrote:

> 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.


Also--and this is really the opposite side of the same coin--once the
language gives a meaning to -x as an expression, -42 gains an analogous
meaning automatically. Therefore, not only is there no need to define a
meaning for - as part of a literal, but doing so would run the risk of
introducing an ambiguity.


 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-04-2008
* Andrew Koenig:
> "James Kanze" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
> <(E-Mail Removed)> wrote:
>
>> 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.

>
> Also--and this is really the opposite side of the same coin--once the
> language gives a meaning to -x as an expression, -42 gains an analogous
> meaning automatically. Therefore, not only is there no need to define a
> meaning for - as part of a literal, but doing so would run the risk of
> introducing an ambiguity.


I started to write that I disagreed about the "no need", considering
e.g. LONG_MIN and "a--5" versus "a+-5" (consistency, least surprise),
but then I thought about "a=-5"...

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[floating-literal] Mihai Vasilian C++ 1 09-13-2011 10:29 PM
floating-point literal cannot appear in a constant-expression TimC C++ 2 03-07-2009 09:51 AM
floating-point literal cannot appear in a constant-expression TimC C Programming 6 03-07-2009 01:11 AM
State definition and display: literal vs. symbolic in ModelSim Paul Urbanus VHDL 4 01-12-2005 03:40 AM
What's wrong with rpc-literal? Why use doc-literal? Anonieko Ramos ASP .Net Web Services 0 09-27-2004 09:06 AM



Advertisments