Velocity Reviews > C++ > negative integer literals

# negative integer literals

Ivan Novick
Guest
Posts: n/a

 12-10-2006
Hi,

Is it possible to have negative integer literal or only positive?

As far as I understand, the code below would be a positive integer
literal and the unary negative operator.

x = -3.2;

Thanks,
Ivan
http://www.0x4849.net

red floyd
Guest
Posts: n/a

 12-10-2006
Ivan Novick wrote:
> Hi,
>
> Is it possible to have negative integer literal or only positive?
>
> As far as I understand, the code below would be a positive integer
> literal and the unary negative operator.
>
> x = -3.2;
>
> Thanks,
> Ivan
> http://www.0x4849.net
>

Actually, it's a negative *double* literal.

red floyd
Guest
Posts: n/a

 12-10-2006
Ivan Novick wrote:
> Hi,
>
> Is it possible to have negative integer literal or only positive?
>
> As far as I understand, the code below would be a positive integer
> literal and the unary negative operator.
>
> x = -3.2;
>

Pardon me. It's not a literal at all. It's an expression (of undefined
type, since you don't define x).

-3.2 is a negative double literal.

Gianni Mariani
Guest
Posts: n/a

 12-10-2006
red floyd wrote:
....
>>

>
> Pardon me. It's not a literal at all. It's an expression (of undefined
> type, since you don't define x).
>
> -3.2 is a negative double literal.

I thought -3.2 was a double float literal.

Ivan Novick
Guest
Posts: n/a

 12-10-2006
red floyd wrote:
> Ivan Novick wrote:
> > Hi,
> >
> > Is it possible to have negative integer literal or only positive?
> >
> > As far as I understand, the code below would be a positive integer
> > literal and the unary negative operator.
> >
> > x = -3.2;
> >

>
> Pardon me. It's not a literal at all. It's an expression (of undefined
> type, since you don't define x).
>
> -3.2 is a negative double literal.

Yes, clearly its a double not integer, that was a typo. and obvioussly
x must be delcared. The point is, is it a negative literal or a
positive literal combined with a unary negative operator? In the C++
standard i see no description at all regarding negative literals.

Ivan
http://www.0x4849.net

John Carson
Guest
Posts: n/a

 12-10-2006
"Ivan Novick" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com
> red floyd wrote:
>> Ivan Novick wrote:
>>> Hi,
>>>
>>> Is it possible to have negative integer literal or only positive?
>>>
>>> As far as I understand, the code below would be a positive integer
>>> literal and the unary negative operator.
>>>
>>> x = -3.2;
>>>

>>
>> Pardon me. It's not a literal at all. It's an expression (of
>> undefined type, since you don't define x).
>>
>> -3.2 is a negative double literal.

>
> Yes, clearly its a double not integer, that was a typo. and obvioussly
> x must be delcared. The point is, is it a negative literal or a
> positive literal combined with a unary negative operator? In the C++
> standard i see no description at all regarding negative literals.

I think you are right. These matters are discussed in section 2.13 of the
Standard, and I see no reference to the possibility of a negative integer or
floating literal.

--
John Carson

Gavin Deane
Guest
Posts: n/a

 12-10-2006

Gianni Mariani wrote:
> I thought -3.2 was a double float literal.

There's no such thing as a "double float". double and float are
mutually exclusive.

Gavin Deane

Gianni Mariani
Guest
Posts: n/a

 12-10-2006
Gavin Deane wrote:
> Gianni Mariani wrote:
>> I thought -3.2 was a double float literal.

>
> There's no such thing as a "double float". double and float are
> mutually exclusive.

double floating point...

PICKY !

benben
Guest
Posts: n/a

 12-10-2006
Ivan Novick wrote:
> red floyd wrote:
>> Ivan Novick wrote:
>>> Hi,
>>>
>>> Is it possible to have negative integer literal or only positive?
>>>
>>> As far as I understand, the code below would be a positive integer
>>> literal and the unary negative operator.
>>>
>>> x = -3.2;
>>>

>> Pardon me. It's not a literal at all. It's an expression (of undefined
>> type, since you don't define x).
>>
>> -3.2 is a negative double literal.

>
> Yes, clearly its a double not integer, that was a typo. and obvioussly
> x must be delcared. The point is, is it a negative literal or a
> positive literal combined with a unary negative operator? In the C++
> standard i see no description at all regarding negative literals.

If you pull the - and 3.2 apart it still compiles fine. They are parsed
as separate lexical tokens.

I am confident but not completely sure that compilers treat the
expression as a negation applied to the positive literal. However, even
the dumbest compiler will not actually emit code the do that actual
negation at runtime. So either case the outcome is the same. -3.2 is,
well, just -3.2, whichever way you take it.

>
> Ivan
> http://www.0x4849.net
>

Ben

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a

 12-10-2006
On 2006-12-10 08:05, Ivan Novick wrote:
> Hi,
>
> Is it possible to have negative integer literal or only positive?
>
> As far as I understand, the code below would be a positive integer
> literal and the unary negative operator.
>
> x = -3.2;

I really hate to ask, but does it matter if it's a positive literal with
an operator or a negative literal?

--
Erik Wikström