Definition of floating literal in C++ standard



 DEVELOP > c-Plus-Plus > Definition of floating literal in C++ standard

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 02 Feb 2008 05:05:27 PM
Object: Definition of floating literal in C++ standard
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
.

User: "Jerry Coffin"

Title: Re: Definition of floating literal in C++ standard 02 Feb 2008 06:06:32 PM
In article <8b39194f-6996-4664-99c6-4e5e4dafb2a4
@l32g2000hse.googlegroups.com>,
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.
.
User: "Dominic Connor, Quant Headhunter"

Title: Re: Definition of floating literal in C++ standard 03 Feb 2008 06:22:15 AM

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 ?
.
User: "James Kanze"

Title: Re: Definition of floating literal in C++ standard 03 Feb 2008 11:09:20 AM
On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
<dominic.con...@gmail.com> 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:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.
User: "Andrew Koenig"

Title: Re: Definition of floating literal in C++ standard 04 Feb 2008 12:28:52 PM
"James Kanze" <james.kanze@gmail.com> wrote in message
news:00fd1ab6-5050-4cbd-9611-710a1a4d65f9@c4g2000hsg.googlegroups.com...
On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
<dominic.con...@gmail.com> 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.
.
User: "Alf P. Steinbach"

Title: Re: Definition of floating literal in C++ standard 04 Feb 2008 01:18:55 PM
* Andrew Koenig:

"James Kanze" <james.kanze@gmail.com> wrote in message
news:00fd1ab6-5050-4cbd-9611-710a1a4d65f9@c4g2000hsg.googlegroups.com...
On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
<dominic.con...@gmail.com> 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?
.






  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER