Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
September 01, 2011 Is integer overflow defined? | ||||
---|---|---|---|---|
| ||||
Is integer overflow defined (for instance, as being mod 2^size)? Can I reliably say that -long.min == 0L? |
September 01, 2011 Re: Is integer overflow defined? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Eskapp | On 09/01/2011 06:20 PM, Sean Eskapp wrote:
> Is integer overflow defined (for instance, as being mod 2^size)?
I am quite sure that all operations are defined as operations on two's complement integers, which would mean overflow is defined, but I cannot find the respective part of the specification...
> Can I reliably say that -long.min == 0L?
Well no, -long.min == long.min .
according to TDPL p53., that fact is defined. (unary minus: -x == ~x+1)
|
September 01, 2011 Re: Is integer overflow defined? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | == Quote from Timon Gehr (timon.gehr@gmx.ch)'s article
> On 09/01/2011 06:20 PM, Sean Eskapp wrote:
> > Is integer overflow defined (for instance, as being mod 2^size)?
> I am quite sure that all operations are defined as operations on two's
> complement integers, which would mean overflow is defined, but I cannot
> find the respective part of the specification...
> > Can I reliably say that -long.min == 0L?
> Well no, -long.min == long.min .
> according to TDPL p53., that fact is defined. (unary minus: -x == ~x+1)
Ah, good points, thanks!
|
September 02, 2011 Re: Is integer overflow defined? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Timon Gehr:
> according to TDPL p53., that fact is defined. (unary minus: -x == ~x+1)
Uhmmmm.
Bye,
bearophile
|
September 02, 2011 Re: Is integer overflow defined? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 09/02/2011 02:45 AM, bearophile wrote:
> Timon Gehr:
>
>> according to TDPL p53., that fact is defined. (unary minus: -x == ~x+1)
>
> Uhmmmm.
>
> Bye,
> bearophile
For unsigned integers it is clearly defined:
1000... => 0111... => 1000...
And according to TDPL p53: "This manipulation does not raise particular questions about the signedness of val".
So, it is guaranteed that it will work for long.min .
|
Copyright © 1999-2021 by the D Language Foundation