Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648

Hans-Peter Diettrich <DrDiettrich@compuserve.de>
2 Feb 2006 11:35:41 -0500

          From comp.compilers

Related articles
[4 earlier articles]
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 gneuner2@comcast.net (George Neuner) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 rivers@dignus.com (Thomas David Rivers) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 david@tribble.com (David R Tribble) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 henry@spsystems.net (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-02-02)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-02-02)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 david@tribble.com (David R Tribble) (2006-02-03)
| List of all articles for this month |

From: Hans-Peter Diettrich <DrDiettrich@compuserve.de>
Newsgroups: comp.compilers
Date: 2 Feb 2006 11:35:41 -0500
Organization: Compilers Central
References: 06-01-131
Keywords: arithmetic, lex
Posted-Date: 02 Feb 2006 11:35:41 EST

Edsko de Vries wrote:


> This works fine, with the sole exception of the number "-2147483648".
> The problem is, of course, overflow: -2147483648 is a valid negative
> number (assuming 32-bit numbers), but the integer 2147483648 is _not_ a
> valid positive number. Thus, the above method of dealing with "-" as a
> unary operator breaks down.


When you separate the sign from the numbers, you should use unsigned
values to prevent overflows. Shouldn't your code also accept unsigned
integers > 2^31?


DoDi



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.