473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

negative integer literals

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

Dec 10 '06 #1
15 3343
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.
Dec 10 '06 #2
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.
Dec 10 '06 #3
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.
Dec 10 '06 #4
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

Dec 10 '06 #5
"Ivan Novick" <iv**@0x4849.netwrote in message
news:11**********************@f1g2000cwa.googlegro 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
Dec 10 '06 #6

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

Dec 10 '06 #7
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 !
Dec 10 '06 #8
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
Dec 10 '06 #9
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
Dec 10 '06 #10
red floyd wrote:
>
Actually, it's a negative *double* literal.
Actually, there are no such things as negative literals
at ALL.

The OP question (after you omit the integer / real confusion)
is that YES it is an expression made up of a unary minus and
an non-signed literal.

Of course, it is still a "constant expression" according to
the spec. For integer constant expressions, this pretty
much requires them to be evaluated at compile time so they
act like a literal. The only time it gets hairy is in
the case where the number after the minus sign is 2**nbit-1
where nbit is the number of bits in an int.
Dec 10 '06 #11
* Erik Wikström:
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?
It matters for whether the most negative value can be expressed legally
as a literal.

--
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?
Dec 10 '06 #12
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.
Right: literals are non-negative values, and a leading minus sign is a
separate token. Off the top of my head, I don't see that there's a
significant difference from having a single token that includes the
leading minus sign.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 10 '06 #13
Erik Wikström wrote:
>
I really hate to ask, but does it matter if it's a positive literal with
an operator or a negative literal?
It matters when numeric types have an asymmetrical range. The most
common place where some of us run into it is:

#define INT_MAX 32767
#define INT_MIN -32768

The problem here is that the type of INT_MIN is not int, but long. (That
example is for a 16-bit architecture, but the same problem arises for
all sizes of asymmetric types).

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 10 '06 #14
Pete Becker 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.

Right: literals are non-negative values, and a leading minus sign is a
separate token. Off the top of my head, I don't see that there's a
significant difference from having a single token that includes the
leading minus sign.
Okay, I also posted an example where it matters. But that's an odd
corner, occupied by standard library writers.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 10 '06 #15
benben <benhonghatgmaildotcom@nospamwrote:
>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.
We had a discussion on "reducing constant expressions at runtime"
awhile back. Not surprisingly, there was not total agreement
on the above point.

Steve
Dec 10 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Danny Winslow | last post by:
I get an unexpected result when I add two negative numbers in PHP on SPARC/Solaris 8. The same program works fine on Intel/Linux. I'm using PHP 4.3.1 on both systems. Here is my program,...
19
by: Imbaud Pierre | last post by:
integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more...
16
by: Stefan Wallentowitz | last post by:
Hello together! I'm searching for a statistic about the value ranges of integers in a set of "standard" c-programs. I'm specifically interested in the avarage ratio of assignments etc. of...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
39
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer,...
5
by: bradeck | last post by:
A question recently came up of late in some interviewing techniques discussions and I vaguely remember this being an ANSI C++ related issue but cannot remember the specifics. Basically if you have...
7
by: Gary Brown | last post by:
Hi, I have a whole bunch of integer constants that are best given in octal (PDP-1 opcodes). It makes a huge difference in readability and authenticity if these can be entered in octal. I...
8
by: valentin tihomirov | last post by:
My rateonale is: -1 mod 3 = must be 3 0 mod 3 = 0 1 mod 3 = 1 2 mod 3 = 2 3 mod 3 = 3 4 mod 3 = 0 = 1 = 2 = 3
6
by: ariel ledesma | last post by:
hello guys i just ran into this when comparing negative numbers, they start returning False from -6 down, but only when comparing with 'is' True False True i read that 'is' compares if...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.