Definition of floating literal in C++ standard

Discussion in 'C++' started by murali.desikan@gmail.com, Feb 2, 2008.

  1. Guest

    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, 2008
    #1
    1. Advertising

  2. Jerry Coffin Guest

    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.
    Jerry Coffin, Feb 3, 2008
    #2
    1. Advertising

  3. > 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 ?
    Dominic Connor, Quant Headhunter, Feb 3, 2008
    #3
  4. James Kanze Guest

    On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
    <> 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:
    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
    James Kanze, Feb 3, 2008
    #4
  5. "James Kanze" <> wrote in message
    news:...
    On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
    <> 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.
    Andrew Koenig, Feb 4, 2008
    #5
  6. * Andrew Koenig:
    > "James Kanze" <> wrote in message
    > news:...
    > On Feb 3, 1:22 pm, "Dominic Connor, Quant Headhunter"
    > <> 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?
    Alf P. Steinbach, Feb 4, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Urbanus
    Replies:
    4
    Views:
    3,333
    Tim Hubberstey
    Jan 12, 2005
  2. TimC
    Replies:
    6
    Views:
    2,077
    CBFalconer
    Mar 7, 2009
  3. TimC
    Replies:
    2
    Views:
    4,415
    James Kanze
    Mar 7, 2009
  4. Mihai Vasilian

    [floating-literal]

    Mihai Vasilian, Sep 13, 2011, in forum: C++
    Replies:
    1
    Views:
    376
    jacob navia
    Sep 13, 2011
  5. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    366
    Anonieko Ramos
    Sep 27, 2004
Loading...

Share This Page