| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
December 30, 2015 Bug? or do I something wrong | ||||
|---|---|---|---|---|
| ||||
import std.stdio;
void main() {
auto x = 9223372036854775807L;
auto x2 = 9223372036854775807L + 1;
long x3 = -9223372036854775808U;
//auto x4 = -9223372036854775808L; //Error: signed integer overflow
writeln(x + 1); //-9223372036854775808
writeln(x2); //-9223372036854775808
writeln(x3); //-9223372036854775808
//writeln(x4);
}
| ||||
December 30, 2015 Re: Bug? or do I something wrong | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | On Wednesday, 30 December 2015 at 14:07:54 UTC, Daniel Kozak wrote:
> import std.stdio;
>
> void main() {
>
> auto x = 9223372036854775807L;
> auto x2 = 9223372036854775807L + 1;
> long x3 = -9223372036854775808U;
> //auto x4 = -9223372036854775808L; //Error: signed integer overflow
>
> writeln(x + 1); //-9223372036854775808
> writeln(x2); //-9223372036854775808
> writeln(x3); //-9223372036854775808
> //writeln(x4);
> }
I reported this bug about 2-3 months ago, and people said something like it is same in C, and was reported a long time ago etc. So, nothing is changing about it.
| |||
December 30, 2015 Re: Bug? or do I something wrong | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | On 12/30/15 9:07 AM, Daniel Kozak wrote:
> import std.stdio;
>
> void main() {
>
> auto x = 9223372036854775807L;
> auto x2 = 9223372036854775807L + 1;
> long x3 = -9223372036854775808U;
> //auto x4 = -9223372036854775808L; //Error: signed integer overflow
Not a bug.
This is parsed as - (9223372036854775808L)
That number cannot be represented in signed long, so it fails.
The only correct thing to do is via x3.
-Steve
| |||
December 30, 2015 Re: Bug? or do I something wrong | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Wednesday, 30 December 2015 at 20:13:46 UTC, Steven Schveighoffer wrote:
> On 12/30/15 9:07 AM, Daniel Kozak wrote:
>> import std.stdio;
>>
>> void main() {
>>
>> auto x = 9223372036854775807L;
>> auto x2 = 9223372036854775807L + 1;
>> long x3 = -9223372036854775808U;
>> //auto x4 = -9223372036854775808L; //Error: signed integer overflow
>
> Not a bug.
>
> This is parsed as - (9223372036854775808L)
>
> That number cannot be represented in signed long, so it fails.
>
> The only correct thing to do is via x3.
>
> -Steve
Thanks :)
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply