Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > negative integer literals

Reply
Thread Tools

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

 
Reply With Quote
 
 
 
 
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.
 
Reply With Quote
 
 
 
 
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.
 
Reply With Quote
 
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.
 
Reply With Quote
 
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

 
Reply With Quote
 
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


 
Reply With Quote
 
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

 
Reply With Quote
 
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 !
 
Reply With Quote
 
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
 
Reply With Quote
 
=?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
 
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
Integer Literals bradeck@gmail.com C++ 5 10-19-2006 02:31 PM
Java: byte literals and short literals John Goche Java 8 01-17-2006 11:12 PM
Template argument deduction on integer literals Bart Samwel C++ 14 04-22-2005 10:03 PM
Generic class literals - e.g,, Class<Map<String, Integer>>.class Purush Java 4 04-13-2005 08:40 PM
Negative setup and Negative hold prem_eda VHDL 5 10-11-2004 12:14 PM



Advertisments